shipperhq_shipperhq - Version 2.52.0

Version Notes

Accessorial support in admin

Download this release

Release Info

Developer Karen Baker
Extension shipperhq_shipperhq
Version 2.52.0
Comparing to
See all releases


Version 2.52.0

Files changed (121) hide show
  1. app/code/community/Shipperhq/Frontend/Block/Adminhtml/Sales/Order/Create/Shipping/Method/Form.php +135 -0
  2. app/code/community/Shipperhq/Frontend/Block/Catalog/Helper.php +226 -0
  3. app/code/community/Shipperhq/Frontend/Block/Catalog/Shipresults.php +94 -0
  4. app/code/community/Shipperhq/Frontend/Block/Checkout/AbstractBlock.php +52 -0
  5. app/code/community/Shipperhq/Frontend/Block/Checkout/Helper.php +698 -0
  6. app/code/community/Shipperhq/Frontend/Block/Checkout/Multishipping/Shipping.php +122 -0
  7. app/code/community/Shipperhq/Frontend/Block/Checkout/Onepage/Progress.php +52 -0
  8. app/code/community/Shipperhq/Frontend/Block/Checkout/Onepage/Shipping/Method/Available.php +158 -0
  9. app/code/community/Shipperhq/Frontend/Model/Checkout/Type/Multishipping.php +181 -0
  10. app/code/community/Shipperhq/Frontend/etc/config.xml +9 -0
  11. app/code/community/Shipperhq/Migration/Block/Adminhtml/Migration.php +48 -0
  12. app/code/community/Shipperhq/Migration/Block/Adminhtml/Migration/Edit/Form.php +35 -0
  13. app/code/community/Shipperhq/Migration/Block/Adminhtml/Migration/Migratable.php +214 -0
  14. app/code/community/Shipperhq/Migration/Helper/Data.php +152 -0
  15. app/code/community/Shipperhq/Migration/Model/Migrate.php +271 -0
  16. app/code/community/Shipperhq/Migration/Model/Product/Action.php +152 -0
  17. app/code/community/Shipperhq/Migration/Model/Resource/Iterator/Batched.php +63 -0
  18. app/code/community/Shipperhq/Migration/controllers/Adminhtml/Shqmigration/AjaxController.php +140 -0
  19. app/code/community/Shipperhq/Migration/controllers/Adminhtml/ShqmigrationController.php +76 -0
  20. app/code/community/Shipperhq/Migration/etc/adminhtml.xml +67 -0
  21. app/code/community/Shipperhq/Migration/etc/config.xml +85 -0
  22. app/code/community/Shipperhq/Migration/etc/migrate.xml +95 -0
  23. app/code/community/Shipperhq/Paypalexpress/Model/Express/Checkout.php +126 -0
  24. app/code/community/Shipperhq/Paypalexpress/etc/config.xml +47 -0
  25. app/code/community/Shipperhq/Pbint/Block/Adminhtml/System/Upload.php +73 -0
  26. app/code/community/Shipperhq/Pbint/Block/Sales/Order/Duty.php +55 -0
  27. app/code/community/Shipperhq/Pbint/Helper/Data.php +64 -0
  28. app/code/community/Shipperhq/Pbint/Model/Catalog/Category.php +180 -0
  29. app/code/community/Shipperhq/Pbint/Model/Catalog/Cron.php +151 -0
  30. app/code/community/Shipperhq/Pbint/Model/Catalog/File.php +862 -0
  31. app/code/community/Shipperhq/Pbint/Model/Catalog/Product.php +244 -0
  32. app/code/community/Shipperhq/Pbint/Model/Credentials.php +78 -0
  33. app/code/community/Shipperhq/Pbint/Model/Creditmemo/Duty.php +75 -0
  34. app/code/community/Shipperhq/Pbint/Model/Helper.php +224 -0
  35. app/code/community/Shipperhq/Pbint/Model/Inboundparcel.php +40 -0
  36. app/code/community/Shipperhq/Pbint/Model/Invoice/Duty.php +79 -0
  37. app/code/community/Shipperhq/Pbint/Model/Mysql4/Inboundparcel.php +39 -0
  38. app/code/community/Shipperhq/Pbint/Model/Mysql4/Inboundparcel/Collection.php +39 -0
  39. app/code/community/Shipperhq/Pbint/Model/Mysql4/Ordernumber.php +39 -0
  40. app/code/community/Shipperhq/Pbint/Model/Mysql4/Ordernumber/Collection.php +39 -0
  41. app/code/community/Shipperhq/Pbint/Model/Mysql4/Variable.php +39 -0
  42. app/code/community/Shipperhq/Pbint/Model/Mysql4/Variable/Collection.php +39 -0
  43. app/code/community/Shipperhq/Pbint/Model/Observer.php +171 -0
  44. app/code/community/Shipperhq/Pbint/Model/Ordernumber.php +40 -0
  45. app/code/community/Shipperhq/Pbint/Model/Pdf/Duty.php +41 -0
  46. app/code/community/Shipperhq/Pbint/Model/Quote/Duty.php +90 -0
  47. app/code/community/Shipperhq/Pbint/Model/Resource/Mysql4/Setup.php +33 -0
  48. app/code/community/Shipperhq/Pbint/Model/Variable.php +40 -0
  49. app/code/community/Shipperhq/Pbint/README +2 -0
  50. app/code/community/Shipperhq/Pbint/changelog.txt +0 -0
  51. app/code/community/Shipperhq/Pbint/controllers/Adminhtml/ShqpitneyController.php +66 -0
  52. app/code/community/Shipperhq/Pbint/etc/config.xml +248 -0
  53. app/code/community/Shipperhq/Pbint/etc/system.xml +162 -0
  54. app/code/community/Shipperhq/Pbint/sql/shqpbint_setup/mysql4-install-1.0.0.php +72 -0
  55. app/code/community/Shipperhq/Pbint/sql/shqpbint_setup/mysql4-install-1.0.1.php +73 -0
  56. app/code/community/Shipperhq/Pbint/sql/shqpbint_setup/mysql4-upgrade-1.0.0-1.0.1.php +29 -0
  57. app/code/community/Shipperhq/Shipper/Block/Adminhtml/Carrier/About.php +72 -0
  58. app/code/community/Shipperhq/Shipper/Block/Adminhtml/Carrier/Heading.php +48 -0
  59. app/code/community/Shipperhq/Shipper/Block/Adminhtml/Carrier/Refreshcarriers.php +74 -0
  60. app/code/community/Shipperhq/Shipper/Block/Adminhtml/Catalog/Product/Edit/Tab/Dimensional.php +50 -0
  61. app/code/community/Shipperhq/Shipper/Block/Adminhtml/Synchronize.php +57 -0
  62. app/code/community/Shipperhq/Shipper/Block/Adminhtml/Synchronize/Grid.php +96 -0
  63. app/code/community/Shipperhq/Shipper/Block/Adminhtml/Synchronize/Notify.php +97 -0
  64. app/code/community/Shipperhq/Shipper/Block/Adminhtml/System/Config/Fieldset/Shipper/Hint.php +51 -0
  65. app/code/community/Shipperhq/Shipper/Helper/Data.php +1026 -0
  66. app/code/community/Shipperhq/Shipper/Helper/Mapper.php +48 -0
  67. app/code/community/Shipperhq/Shipper/Model/Adminhtml/System/Config/Source/Carriers.php +57 -0
  68. app/code/community/Shipperhq/Shipper/Model/Adminhtml/System/Config/Source/Environmentscope.php +63 -0
  69. app/code/community/Shipperhq/Shipper/Model/Attributeupdate.php +41 -0
  70. app/code/community/Shipperhq/Shipper/Model/Carrier/Backup.php +142 -0
  71. app/code/community/Shipperhq/Shipper/Model/Carrier/Convert/AddressMapper.php +256 -0
  72. app/code/community/Shipperhq/Shipper/Model/Carrier/Convert/OrderMapper.php +274 -0
  73. app/code/community/Shipperhq/Shipper/Model/Carrier/Convert/ShipmentMapper.php +191 -0
  74. app/code/community/Shipperhq/Shipper/Model/Carrier/Convert/ShipperMapper.php +671 -0
  75. app/code/community/Shipperhq/Shipper/Model/Carrier/Shipper.php +1099 -0
  76. app/code/community/Shipperhq/Shipper/Model/Carrier/Shipperadmin.php +105 -0
  77. app/code/community/Shipperhq/Shipper/Model/Checkout/Helper.php +76 -0
  78. app/code/community/Shipperhq/Shipper/Model/Observer.php +439 -0
  79. app/code/community/Shipperhq/Shipper/Model/Observer/Order.php +446 -0
  80. app/code/community/Shipperhq/Shipper/Model/Observer/Shipment.php +107 -0
  81. app/code/community/Shipperhq/Shipper/Model/Order/Packages.php +87 -0
  82. app/code/community/Shipperhq/Shipper/Model/Quote/Packages.php +79 -0
  83. app/code/community/Shipperhq/Shipper/Model/Rate/Result.php +73 -0
  84. app/code/community/Shipperhq/Shipper/Model/Resource/Attributeupdate.php +37 -0
  85. app/code/community/Shipperhq/Shipper/Model/Resource/Attributeupdate/Collection.php +38 -0
  86. app/code/community/Shipperhq/Shipper/Model/Resource/Order/Packages.php +76 -0
  87. app/code/community/Shipperhq/Shipper/Model/Resource/Order/Packages/Collection.php +50 -0
  88. app/code/community/Shipperhq/Shipper/Model/Resource/Quote/Packages.php +76 -0
  89. app/code/community/Shipperhq/Shipper/Model/Resource/Quote/Packages/Collection.php +55 -0
  90. app/code/community/Shipperhq/Shipper/Model/Resource/Storage.php +161 -0
  91. app/code/community/Shipperhq/Shipper/Model/Sales/Quote/Address/Rate.php +73 -0
  92. app/code/community/Shipperhq/Shipper/Model/Session.php +41 -0
  93. app/code/community/Shipperhq/Shipper/Model/Source/Freight/Freightclass.php +73 -0
  94. app/code/community/Shipperhq/Shipper/Model/Source/Validation/Result.php +105 -0
  95. app/code/community/Shipperhq/Shipper/Model/Storage.php +242 -0
  96. app/code/community/Shipperhq/Shipper/Model/Storage/Manager.php +67 -0
  97. app/code/community/Shipperhq/Shipper/Model/Synchronize.php +432 -0
  98. app/code/community/Shipperhq/Shipper/changelog.txt +82 -0
  99. app/code/community/Shipperhq/Shipper/controllers/Adminhtml/ShqajaxController.php +63 -0
  100. app/code/community/Shipperhq/Shipper/controllers/Adminhtml/ShqsynchronizeController.php +96 -0
  101. app/code/community/Shipperhq/Shipper/etc/adminhtml.xml +70 -0
  102. app/code/community/Shipperhq/Shipper/etc/config.xml +523 -0
  103. app/code/community/Shipperhq/Shipper/etc/system.xml +286 -0
  104. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.10.php +502 -0
  105. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.11.php +526 -0
  106. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.12.php +556 -0
  107. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.13.php +568 -0
  108. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.14.php +548 -0
  109. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.15.php +567 -0
  110. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.16.php +461 -0
  111. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.17.php +444 -0
  112. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.18.php +624 -0
  113. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.19.php +629 -0
  114. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.20.php +634 -0
  115. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.21.php +645 -0
  116. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.22.php +649 -0
  117. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.23.php +671 -0
  118. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.24.php +690 -0
  119. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.25.php +816 -0
  120. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.26.php +836 -0
  121. app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.27.php +354 -0
app/code/community/Shipperhq/Frontend/Block/Adminhtml/Sales/Order/Create/Shipping/Method/Form.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shipperhq_Frontend_Block_Adminhtml_Sales_Order_Create_Shipping_Method_Form
4
+ extends Mage_Adminhtml_Block_Sales_Order_Create_Shipping_Method_Form
5
+ {
6
+ /**
7
+ * Returns a helper block, that is used to retrieve all data
8
+ *
9
+ * @return Shipperhq_Frontend_Block_Checkout_Helper
10
+ */
11
+ public function getHelperBlock()
12
+ {
13
+ if ($this->_helperBlock === null) {
14
+ $this->_helperBlock = $this->getLayout()->createBlock(
15
+ 'shipperhq_frontend/checkout_helper',
16
+ sprintf('%s.helper', $this->getNameInLayout())
17
+ );
18
+
19
+ $this->_helperBlock->init(array(
20
+ 'calendar_block' => 'shipperhq_calendar/adminhtml_sales_order_create_shipping_method_calendar',
21
+ 'calendar_template' => 'shipperhq/calendar/sales/order/create/shipping_method/calendar.phtml',
22
+ 'pickup_block' => 'shipperhq_pickup/adminhtml_sales_order_create_shipping_method_storepickup',
23
+ 'pickup_template' => 'shipperhq/pickup/sales/order/create/shipping_method/storepickup.phtml',
24
+ 'accessorials_block' => 'shipperhq_freight/adminhtml_sales_order_create_shipping_method_accessorials',
25
+ 'accessorials_template' => 'shipperhq/freight/sales/order/create/shipping_method/accessorials.phtml',
26
+ 'quote' => $this->getQuote(),
27
+ 'address' => $this->getAddress()
28
+ ));
29
+ }
30
+
31
+
32
+ return $this->_helperBlock;
33
+ }
34
+
35
+ public function getCarrierGroupRates()
36
+ {
37
+ return $this->getHelperBlock()->getCarrierGroupRates();
38
+ }
39
+
40
+ public function getProcessedShippingRates()
41
+ {
42
+ return $this->getHelperBlock()->getProcessedShippingRates($this->getShippingRates());
43
+ }
44
+
45
+ public function adminShippingEnabled()
46
+ {
47
+ return Mage::getStoreConfigFlag('carriers/shipper/custom_admin');
48
+ }
49
+
50
+ /*
51
+ * Retrieves the items details ready for printing to checkout when < 2 carrier groups are in checkout
52
+ */
53
+ public function getSingleItemDetails($shippingRates)
54
+ {
55
+ return $this->getHelperBlock()->getSingleItemDetails($shippingRates);
56
+ }
57
+
58
+ /**
59
+ * Populates the location select dropdown
60
+ * @return string
61
+ */
62
+ public function getShippingMethodsSelect($name, $id, $value, $rates, $sole)
63
+ {
64
+ return $this->getHelperBlock()->getShippingMethodsSelect($name, $id, $value, $rates, $sole);
65
+ }
66
+
67
+ public function getAddressShippingMethod()
68
+ {
69
+ return $this->getHelperBlock()->getAddressShippingMethod();
70
+ }
71
+
72
+ public function isShippingMethodSelected($rates)
73
+ {
74
+ return $this->getHelperBlock()->isShippingMethodSelected($rates);
75
+ }
76
+
77
+ public function getShippingPrice($price, $flag, $includeContainer = true)
78
+ {
79
+ return $this->getHelperBlock()->getShippingPrice($price, $flag, $includeContainer);
80
+ }
81
+
82
+ public function showToolTips() {
83
+ return $this->getHelperBlock()->showToolTips();
84
+ }
85
+
86
+ public function getToolTipText()
87
+ {
88
+ return $this->getHelperBlock()->getToolTipText();
89
+ }
90
+
91
+ public function getMethodTitle($methodTitle, $methodDescription, $includeContainer)
92
+ {
93
+ return $this->getHelperBlock()->getMethodTitle($methodTitle, $methodDescription, $includeContainer);
94
+ }
95
+
96
+ protected function getFormattedItemList($items)
97
+ {
98
+ return $this->getHelperBlock()->getFormattedItemList($items);
99
+ }
100
+
101
+ public function getCarrierGroupAddressShippingMethod($carrierGroup)
102
+ {
103
+ return $this->getHelperBlock()->getCarrierGroupAddressShippingMethod($carrierGroup);
104
+ }
105
+
106
+ public function showItemDescription()
107
+ {
108
+ return $this->getHelperBlock()->showItemDescription();
109
+ }
110
+
111
+ public function getStorepickupHtml($carrierCode, $carrierType, $carriergroup = null )
112
+ {
113
+ return $this->getHelperBlock()->getStorepickupHtml($carrierCode, $carrierType, $carriergroup);
114
+ }
115
+
116
+ public function getCalendarHtml($carriergroup, $code, $soleMethod = false)
117
+ {
118
+ return $this->getHelperBlock()->getCalendarHtml($carriergroup, $code, $soleMethod);
119
+ }
120
+
121
+ public function isPickupCarrier($rate)
122
+ {
123
+ return $this->getHelperBlock()->isPickupCarrier($rate);
124
+ }
125
+
126
+ public function isFreightCarrier($rate)
127
+ {
128
+ return $this->getHelperBlock()->isFreightCarrier($rate);
129
+ }
130
+
131
+ public function getFreightAccessorialsHtml($carrierCode, $carrierType, $carrerigroup = '')
132
+ {
133
+ return $this->getHelperBlock()->getFreightAccessorialsHtml($carrerigroup, $carrierCode, $carrierType);
134
+ }
135
+ }
app/code/community/Shipperhq/Frontend/Block/Catalog/Helper.php ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shipperhq_Frontend_Block_Catalog_Helper
4
+ extends Mage_Core_Block_Template
5
+ {
6
+
7
+ private static $_debug;
8
+
9
+ protected $_storepickup;
10
+ protected $_calendar;
11
+ protected $_rates;
12
+ protected $_accessorial;
13
+
14
+
15
+ /**
16
+ * Calendar block name
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_calendarBlockType;
21
+
22
+ /**
23
+ * Calendar block template
24
+ *
25
+ * @var string
26
+ */
27
+ protected $_calendarBlockTemplate;
28
+
29
+ /**
30
+ * Store pickup block name
31
+ *
32
+ * @var string
33
+ */
34
+ protected $_storePickupBlockType;
35
+
36
+ /**
37
+ * Store pickup block template
38
+ *
39
+ * @var string
40
+ */
41
+ protected $_storePickupBlockTemplate;
42
+
43
+ /**
44
+ * Freight accessorials block name
45
+ *
46
+ * @var string
47
+ */
48
+ protected $_freightAccessorialsBlockType;
49
+
50
+ /*
51
+ * Freight accessorials block template
52
+ *
53
+ * @var string
54
+ */
55
+ protected $_freightAccessorialsBlockTemplate;
56
+
57
+ /**
58
+ * Sets debug flag
59
+ */
60
+ protected function _construct() {
61
+ self::$_debug = Mage::helper('wsalogger')->isDebug('Shipperhq_Splitrates');
62
+
63
+ parent::_construct();
64
+
65
+ }
66
+
67
+ /**
68
+ * Sets up block properties
69
+ *
70
+ * @param array $options
71
+ * @return $this
72
+ */
73
+ public function init($options)
74
+ {
75
+ if (isset($options['calendar_block'])) {
76
+ $this->setCalendarBlockType($options['calendar_block']);
77
+ }
78
+ if (isset($options['calendar_template'])) {
79
+ $this->setCalendarBlockTemplate($options['calendar_template']);
80
+ }
81
+ // if (isset($options['pickup_block'])) {
82
+ // $this->setStorePickUpBlockType($options['pickup_block']);
83
+ // }
84
+ // if (isset($options['pickup_template'])) {
85
+ // $this->setStorePickUpBlockTemplate($options['pickup_template']);
86
+ // }
87
+
88
+ return $this;
89
+ }
90
+
91
+ public function isCalendarRate($carrierGroupId, $carrierCode, $carrierType)
92
+ {
93
+ return Mage::helper('shipperhq_calendar')->hasCalendarDetails($carrierGroupId,$carrierCode, $carrierType);
94
+ }
95
+
96
+ public function getCalendarHtml($carriergroup, $code)
97
+ {
98
+
99
+ $block = $this->_getCalendar()
100
+ ->setCarriergroupId($carriergroup)
101
+ ->setCarrierCode($code)
102
+ ->setName('calendar')
103
+ ->setTemplate($this->getCalendarBlockTemplate())
104
+ ->toHtml();
105
+ return $block;
106
+ }
107
+
108
+ public function getStorepickupHtml($carrierCode, $carrierType, $carriergroup = null )
109
+ {
110
+ return $this->_getStorePickup('storepickup_'.$carrierCode)
111
+ ->setCarriergroupId($carriergroup)
112
+ ->setCarrierCode($carrierCode)
113
+ ->setIsAccessPoints(Mage::helper('shipperhq_pickup')->isUpsAccessPointCarrier($carrierType))
114
+ ->setCarrierType($carrierType)
115
+ ->setName('storepickup_'.$carrierCode)
116
+ ->setTemplate($this->getStorePickUpBlockTemplate())
117
+ ->toHtml();
118
+ }
119
+
120
+ protected function _getCalendar($name = '')
121
+ {
122
+ if (!$this->_calendar) {
123
+ $this->_calendar = $this->getLayout()->createBlock($this->getCalendarBlockType(), $name);
124
+ // $this->_calendar->setQuote($this->getQuote());
125
+ // $this->_calendar->setAddress($this->getAddress());
126
+ }
127
+
128
+ return $this->_calendar;
129
+ }
130
+
131
+ protected function _getStorePickup($name)
132
+ {
133
+ $this->_storepickup = $this->getLayout()->createBlock($this->getStorePickUpBlockType(), $name);
134
+ $this->_storepickup->setQuote($this->getQuote());
135
+ $this->_storepickup->setAddress($this->getAddress());
136
+ return $this->_storepickup;
137
+ }
138
+
139
+ /**
140
+ * Returns calendar block type
141
+ *
142
+ * @return string
143
+ */
144
+ public function getCalendarBlockType()
145
+ {
146
+ return $this->_calendarBlockType;
147
+ }
148
+
149
+ /**
150
+ * Sets calendar block type
151
+ *
152
+ * @param string $blockType
153
+ * @return $this
154
+ */
155
+ public function setCalendarBlockType($blockType)
156
+ {
157
+ $this->_calendarBlockType = $blockType;
158
+ return $this;
159
+ }
160
+
161
+ /**
162
+ * Returns calendar block type
163
+ *
164
+ * @return string
165
+ */
166
+ public function getCalendarBlockTemplate()
167
+ {
168
+ return $this->_calendarBlockTemplate;
169
+ }
170
+
171
+ /**
172
+ * Sets calendar block type
173
+ *
174
+ * @param string $blockType
175
+ * @return $this
176
+ */
177
+ public function setCalendarBlockTemplate($blockType)
178
+ {
179
+ $this->_calendarBlockTemplate = $blockType;
180
+ return $this;
181
+ }
182
+
183
+ /**
184
+ * Returns a block type, that should be used for a calendar
185
+ *
186
+ * @return string
187
+ */
188
+ public function getStorePickUpBlockTemplate()
189
+ {
190
+ return $this->_storePickupBlockTemplate;
191
+ }
192
+
193
+ /**
194
+ * Sets store pickup block type
195
+ *
196
+ * @param string $template
197
+ * @return $this
198
+ */
199
+ public function setStorePickUpBlockTemplate($template)
200
+ {
201
+ $this->_storePickupBlockTemplate = $template;
202
+ return $this;
203
+ }
204
+
205
+ /**
206
+ * Returns a block type, that should be used for a calendar
207
+ *
208
+ * @return string
209
+ */
210
+ public function getStorePickUpBlockType()
211
+ {
212
+ return $this->_storePickupBlockType;
213
+ }
214
+
215
+ /**
216
+ * Sets store pickup block type
217
+ *
218
+ * @param $blockType
219
+ * @return $this
220
+ */
221
+ public function setStorePickUpBlockType($blockType)
222
+ {
223
+ $this->_storePickupBlockType = $blockType;
224
+ return $this;
225
+ }
226
+ }
app/code/community/Shipperhq/Frontend/Block/Catalog/Shipresults.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Provides proxy methods for helper block
33
+ *
34
+ * Supplies helper block with render information
35
+ */
36
+ class Shipperhq_Frontend_Block_Catalog_Shipresults extends Mage_Catalog_Block_Product_Abstract
37
+ {
38
+ /**
39
+ * Returns a helper block, that is used to retrieve all data
40
+ *
41
+ * @return Shipperhq_Frontend_Block_Checkout_Helper
42
+ */
43
+ public function getHelperBlock()
44
+ {
45
+ if ($this->_helperBlock === null) {
46
+ $this->_helperBlock = $this->getLayout()->createBlock(
47
+ 'shipperhq_frontend/catalog_helper',
48
+ sprintf('%s.helper', $this->getNameInLayout())
49
+ );
50
+
51
+ //TODO change these
52
+ $this->_helperBlock->init(array(
53
+ 'calendar_block' => 'shipperhq_calendar/catalog_calendar',
54
+ 'calendar_template' => 'shipperhq/calendar/catalog/calendar.phtml',
55
+ // 'pickup_block' => 'shipperhq_pickup/checkout_onepage_shipping_method_storepickup',
56
+ // 'pickup_template' => 'shipperhq/pickup/checkout/onepage/shipping_method/storepickup.phtml',
57
+ //
58
+ ));
59
+ }
60
+
61
+
62
+ return $this->_helperBlock;
63
+ }
64
+
65
+ public function isCalendarRate($carrierGroupId, $carrierCode, $carrierType)
66
+ {
67
+ return $this->getHelperBlock()->isCalendarRate($carrierGroupId, $carrierCode, $carrierType);
68
+ }
69
+
70
+ public function getCalendarHtml($carriergroup, $code, $soleMethod = false)
71
+ {
72
+ return $this->getHelperBlock()->getCalendarHtml($carriergroup, $code);
73
+ }
74
+
75
+ public function getStorepickupHtml($carrierCode, $carrierType, $carriergroup = null )
76
+ {
77
+ return $this->getHelperBlock()->getStorepickupHtml($carrierCode, $carrierType, $carriergroup);
78
+ }
79
+
80
+ public function isPickupCarrier($rate)
81
+ {
82
+ return $this->getHelperBlock()->isPickupCarrier($rate);
83
+ }
84
+
85
+ public function isFreightCarrier($rate)
86
+ {
87
+ return $this->getHelperBlock()->isFreightCarrier($rate);
88
+ }
89
+
90
+ public function getFreightAccessorialsHtml($carrierCode, $carrierType, $carrerigroup = '')
91
+ {
92
+ return $this->getHelperBlock()->getFreightAccessorialsHtml($carrerigroup, $carrierCode, $carrierType);
93
+ }
94
+ }
app/code/community/Shipperhq/Frontend/Block/Checkout/AbstractBlock.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class Shipperhq_Frontend_Block_Checkout_AbstractBlock
4
+ extends Mage_Core_Block_Template
5
+ {
6
+
7
+ /**
8
+ * Quote instance
9
+ *
10
+ * @var Mage_Sales_Model_Quote
11
+ */
12
+ protected $_quote;
13
+
14
+ /**
15
+ * Instance of address for shipping calculations
16
+ *
17
+ * @var Mage_Sales_Model_Quote_Address
18
+ */
19
+ protected $_address;
20
+
21
+ /**
22
+ * @return Mage_Sales_Model_Quote_Address
23
+ */
24
+ public function getAddress()
25
+ {
26
+ if (empty($this->_address)) {
27
+ $this->_address = $this->getQuote()->getShippingAddress();
28
+ }
29
+ return $this->_address;
30
+ }
31
+
32
+ public function setAddress($address)
33
+ {
34
+ $this->_address = $address;
35
+ return $this;
36
+ }
37
+
38
+ public function setQuote(Mage_Sales_Model_Quote $quote)
39
+ {
40
+ $this->_quote = $quote;
41
+ return $this;
42
+ }
43
+
44
+ /**
45
+ * @return Mage_Sales_Model_Quote
46
+ */
47
+ public function getQuote()
48
+ {
49
+ return $this->_quote;
50
+ }
51
+
52
+ }
app/code/community/Shipperhq/Frontend/Block/Checkout/Helper.php ADDED
@@ -0,0 +1,698 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shipperhq_Frontend_Block_Checkout_Helper
4
+ extends Shipperhq_Frontend_Block_Checkout_AbstractBlock
5
+ {
6
+
7
+ private static $_debug;
8
+
9
+ protected $_storepickup;
10
+ protected $_calendar;
11
+ protected $_rates;
12
+ protected $_accessorial;
13
+
14
+
15
+ /**
16
+ * Calendar block name
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_calendarBlockType;
21
+
22
+ /**
23
+ * Calendar block template
24
+ *
25
+ * @var string
26
+ */
27
+ protected $_calendarBlockTemplate;
28
+
29
+ /**
30
+ * Store pickup block name
31
+ *
32
+ * @var string
33
+ */
34
+ protected $_storePickupBlockType;
35
+
36
+ /**
37
+ * Store pickup block template
38
+ *
39
+ * @var string
40
+ */
41
+ protected $_storePickupBlockTemplate;
42
+
43
+ /**
44
+ * Freight accessorials block name
45
+ *
46
+ * @var string
47
+ */
48
+ protected $_freightAccessorialsBlockType;
49
+
50
+ /*
51
+ * Freight accessorials block template
52
+ *
53
+ * @var string
54
+ */
55
+ protected $_freightAccessorialsBlockTemplate;
56
+
57
+ /**
58
+ * Sets debug flag
59
+ */
60
+ protected function _construct() {
61
+ self::$_debug = Mage::helper('wsalogger')->isDebug('Shipperhq_Splitrates');
62
+
63
+ parent::_construct();
64
+
65
+ }
66
+
67
+ /**
68
+ * Sets up block properties
69
+ *
70
+ * @param array $options
71
+ * @return $this
72
+ */
73
+ public function init($options)
74
+ {
75
+ if (isset($options['calendar_block'])) {
76
+ $this->setCalendarBlockType($options['calendar_block']);
77
+ }
78
+ if (isset($options['calendar_template'])) {
79
+ $this->setCalendarBlockTemplate($options['calendar_template']);
80
+ }
81
+ if (isset($options['pickup_block'])) {
82
+ $this->setStorePickUpBlockType($options['pickup_block']);
83
+ }
84
+ if (isset($options['pickup_template'])) {
85
+ $this->setStorePickUpBlockTemplate($options['pickup_template']);
86
+ }
87
+ if (isset($options['accessorials_block'])) {
88
+ $this->setFreightAccessorialsBlockType($options['accessorials_block']);
89
+ }
90
+ if (isset($options['accessorials_template'])) {
91
+ $this->setFreightAccessorialsBlockTemplate($options['accessorials_template']);
92
+ }
93
+ if (isset($options['quote'])) {
94
+ $this->setQuote($options['quote']);
95
+ }
96
+ if (isset($options['address'])) {
97
+ $this->setAddress($options['address']);
98
+ }
99
+
100
+ return $this;
101
+ }
102
+
103
+ public function getCarrierGroupRates()
104
+ {
105
+ self::$_debug = true;
106
+ if (self::$_debug) {
107
+ Mage::helper('wsalogger/log')->postInfo('ShipperHQ','Getting Carrier Group Rates','');
108
+ }
109
+ $shippingRateGroups = $this->getShippingRates();
110
+ if (count($shippingRateGroups)==0) {
111
+ return;
112
+ }
113
+
114
+ $carrierGroupRates=array();
115
+
116
+ $address = $this->getAddress();
117
+ $address->unsetData('cached_items_all');
118
+ $address->unsetData('cached_items_nonnominal');
119
+
120
+ $itemsGrouped = Mage::helper('shipperhq_shipper')->getItemsGroupedByCarrierGroup($address->getAllItems());
121
+ $carrierGroupDescriber = Mage::getStoreConfig(Shipperhq_Shipper_Helper_Data::SHIPPERHQ_SHIPPER_CARRIERGROUP_DESC_PATH)?
122
+ Mage::getStoreConfig(Shipperhq_Shipper_Helper_Data::SHIPPERHQ_SHIPPER_CARRIERGROUP_DESC_PATH) : 'Vendor' ;
123
+ $displayMerged = $address->getCheckoutDisplayMerged() == 1? true : false;
124
+
125
+ $carrierGroupText = array();
126
+ $carrierGroupErrors = array();
127
+ foreach ($shippingRateGroups as $code=>$rates) {
128
+ $tempGroupRates=array();
129
+ foreach ($rates as $rate) {
130
+
131
+ $carriergroup=$rate->getCarriergroupId();
132
+ if(!$displayMerged && is_null($carriergroup)) {
133
+ continue;
134
+ }
135
+ $checkoutText = $rate->getCarriergroup();
136
+ if (array_key_exists($carriergroup,$tempGroupRates)) {
137
+ $tempGroupRates[$carriergroup][]=$rate;
138
+ } else {
139
+ $tempGroupRates[$carriergroup]= array($rate);
140
+ }
141
+ if($rate->getErrorMessage()) {
142
+ $carrierGroupErrors[$carriergroup][$code] = true;
143
+ }
144
+ if(isset($carriergroup) && $checkoutText != '') {
145
+ $carrierGroupText[$carriergroup] = $checkoutText;
146
+ }
147
+ }
148
+
149
+ foreach ($tempGroupRates as $carriergroup=>$rates) {
150
+ if (array_key_exists($carriergroup,$carrierGroupRates)) {
151
+ $carrierGroupRates[$carriergroup]['shipping'][$code] = $rates;
152
+ } else {
153
+ $carrierGroupRates[$carriergroup] = array (
154
+ 'item_list' => false,
155
+ 'shipping' => array(
156
+ $code => $rates
157
+ )
158
+ );
159
+ }
160
+ }
161
+ }
162
+
163
+ foreach ($carrierGroupRates as $carriergroup=>$value) {
164
+ if (array_key_exists($carriergroup,$itemsGrouped)) {
165
+ $carrierGroupRates[$carriergroup]['item_list']= $this->getFormattedItemList(
166
+ $itemsGrouped[$carriergroup]);
167
+ $carrierGroupRates[$carriergroup]['plain_item_list']= $itemsGrouped[$carriergroup];
168
+ }
169
+ if(array_key_exists($carriergroup, $carrierGroupErrors)) {
170
+ $carrierGroupRates[$carriergroup]['error']= $carrierGroupErrors[$carriergroup];
171
+ }
172
+ if(array_key_exists($carriergroup, $carrierGroupText)) {
173
+ $carrierGroupRates[$carriergroup]['checkout_text'] = $carrierGroupText[$carriergroup];
174
+ }
175
+ else {
176
+ $carrierGroupRates[$carriergroup]['checkout_text'] = '';
177
+ }
178
+ $carrierGroupRates[$carriergroup]['carriergroup_text'] = $carrierGroupDescriber;
179
+ }
180
+
181
+ if (self::$_debug) {
182
+ Mage::helper('wsalogger/log')->postInfo('ShipperHQ','Rates display information',$carrierGroupText);
183
+ }
184
+
185
+ return $carrierGroupRates;
186
+ }
187
+
188
+ public function getShippingRates()
189
+ {
190
+
191
+ // if (empty($this->_rates)) {
192
+ $this->getAddress()->collectShippingRates()->save();
193
+ $groups = $this->getAddress()->getGroupedAllShippingRates();
194
+ // return $this->_rates = $groups;
195
+ // }
196
+
197
+ return $groups;//$this->_rates;
198
+ }
199
+
200
+ public function getProcessedShippingRates($shippingRateGroups)
201
+ {
202
+ $processedRates = array();
203
+ $errorArray = array();
204
+ if(is_array($shippingRateGroups)) {
205
+ foreach($shippingRateGroups as $code => $rates)
206
+ {
207
+ foreach($rates as $rate)
208
+ {
209
+ if($rate->getErrorMessage())
210
+ {
211
+ $errorArray[$code] = true;
212
+ }
213
+ }
214
+ }
215
+ }
216
+ $processedRates['shipping'] = $shippingRateGroups;
217
+ if(count($errorArray) > 0 ) {
218
+ $processedRates['error'] = $errorArray;
219
+ }
220
+
221
+ return $processedRates;
222
+ }
223
+
224
+ /*
225
+ * Retrieves the items details ready for printing to checkout when < 2 carrier groups are in checkout
226
+ */
227
+ public function getSingleItemDetails($shippingRates)
228
+ {
229
+ $address = $this->getAddress();
230
+ $formattedItems = array();
231
+
232
+ $itemsGrouped = Mage::helper('shipperhq_shipper')->getItemsGroupedByCarrierGroup($address->getAllItems());
233
+
234
+ if (count($itemsGrouped)>1) {
235
+ if (self::$_debug) {
236
+ Mage::helper('wsalogger/log')->postDebug('ShipperHQ','Single Warehouse','Found more than 1 carrier group so returning');
237
+ }
238
+ return array();
239
+ }
240
+ $checkoutText = '';
241
+
242
+ foreach ($shippingRates as $code=>$rates) {
243
+ foreach ($rates as $rate) {
244
+ $carriergroupShippingDetails = Mage::helper('shipperhq_shipper')->decodeShippingDetails($rate->getCarriergroupShippingDetails());
245
+ foreach($carriergroupShippingDetails as $detail) {
246
+ if(array_key_exists('carriergroup', $detail)) {
247
+ $checkoutText = $detail['carriergroup'];
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ // now format these
254
+ foreach ($itemsGrouped as $carriergroupId=>$items) {
255
+ $formattedItems[] = array (
256
+ 'carriergroupId' => $carriergroupId,
257
+ 'checkout_text' => $checkoutText,
258
+ 'item_list' => $this->getFormattedItemList($items));
259
+ }
260
+ return $formattedItems;
261
+
262
+ }
263
+
264
+ /**
265
+ * Populates the location select dropdown
266
+ * @return string
267
+ */
268
+ public function getShippingMethodsSelect($name, $id, $value, $rates, $sole)
269
+ {
270
+ $options = array();
271
+ $error = false;
272
+ $matchedToSelected = false;
273
+ foreach($rates as $_rate) {
274
+
275
+ if($_rate->getErrorMessage()) {
276
+ $options = '<dt><ul class="messages"><li class="error-msg"><ul><li>'.$_rate->getErrorMessage() .'</li></ul></li></ul></dt>';
277
+
278
+ $error = true;
279
+ break;
280
+ }
281
+ $title = $_rate->getMethodTitle();
282
+ $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax(), false);
283
+ $_incl = $this->getShippingPrice($_rate->getPrice(), true, false);
284
+ $label = $title .' ' .$_excl;
285
+ if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl)
286
+ {
287
+ $label .= ' (' .$this->__('Incl. Tax') .' ' .$_incl .')';
288
+ }
289
+ $options[] = array(
290
+ 'value' => $_rate->getCode(),
291
+ 'label' => $label,
292
+ );
293
+ if($_rate->getCode() == $value) {
294
+ $matchedToSelected = true;
295
+ }
296
+ }
297
+
298
+ if($error) {
299
+ return $options;
300
+ }
301
+
302
+ $select = $this->getLayout()->createBlock('core/html_select')
303
+ ->setName($name)
304
+ ->setId($id)
305
+ ->setClass('shipping-method-select')
306
+ ->setValue($value)
307
+ ->setOptions($options);
308
+ if(!$sole) {
309
+ $select->setExtraParams('hidden="true"');
310
+ }
311
+ if($matchedToSelected) {
312
+ $select->setValue($value);
313
+ }
314
+ return $select->getHtml();
315
+ }
316
+
317
+ public function isShippingMethodSelected($rates)
318
+ {
319
+ $selectedShippingMethod = $this->getAddressShippingMethod();
320
+ foreach($rates as $rate)
321
+ {
322
+ if($rate->getCode() == $selectedShippingMethod) {
323
+ return true;
324
+ }
325
+ }
326
+ return false;
327
+ }
328
+
329
+ public function getShippingPrice($price, $flag, $includeContainer = true)
330
+ {
331
+ return $this->getQuote()->getStore()->convertPrice(Mage::helper('tax')->getShippingPrice($price, $flag, $this->getAddress()), true, $includeContainer);
332
+ }
333
+
334
+ public function getMethodTitle($methodTitle, $methodDescription, $includeContainer)
335
+ {
336
+ $title = $methodTitle;
337
+ if($includeContainer) {
338
+ $truncatedTitle = str_replace($methodDescription, '', $methodTitle);
339
+ $title = '<span class="method-title">'.$truncatedTitle.'</span> <span class="method-extra">'.$methodDescription.'</span>';
340
+ }
341
+ return $title;
342
+ }
343
+
344
+ public function showToolTips() {
345
+ $globals = Mage::helper('shipperhq_shipper')->getGlobalSettings();
346
+ if (!is_array($globals) || !array_key_exists('shippingTooltipText', $globals)
347
+ || $globals['shippingTooltipText'] == '') {
348
+ return false;
349
+ }
350
+ return true;
351
+ }
352
+
353
+ public function getToolTipText()
354
+ {
355
+ $globals = Mage::helper('shipperhq_shipper')->getGlobalSettings();
356
+ if (is_null($globals) || !array_key_exists('shippingTooltipText', $globals)
357
+ || $globals['shippingTooltipText'] == '') {
358
+ return false;
359
+ }
360
+ return addslashes($globals['shippingTooltipText']);
361
+ }
362
+
363
+ protected function getFormattedItemList($items)
364
+ {
365
+ $globals = Mage::helper('shipperhq_shipper')->getGlobalSettings();
366
+ if (is_null($globals)) {
367
+ return array();
368
+ }
369
+ $useParent = true;
370
+ $showAllItems = true;
371
+ $formattedItemList=array();
372
+
373
+ $weightUnit = 'none';
374
+ $showWeight = array_key_exists('dropshipShowWeight', $globals) ? $globals['dropshipShowWeight']: false;
375
+ if($showWeight) {
376
+ $weightUnit = array_key_exists('weightUnit', $globals) ? $globals['weightUnit']: 'none';
377
+ }
378
+
379
+ foreach ($items as $item) {
380
+ if ($item->getParentItem() && ( ($item->getParentItem()->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $useParent && !$showAllItems)
381
+ || $item->getParentItem()->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE )) {
382
+ continue;
383
+ }
384
+
385
+ if (!$useParent && $item->getHasChildren() && $item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE ) {
386
+ continue;
387
+ }
388
+
389
+ if ($item->getHasChildren() && $item->isShipSeparately() && !$useParent) {
390
+ foreach ($item->getChildren() as $child) {
391
+ $formattedItemList[]= self::getStyledHtmlItem(
392
+ 'bundle_child',$child->getQty(),$child->getProduct()->getName(),$child->getWeight(),$weightUnit);
393
+ }
394
+ } else {
395
+ $formattedItemList[] = self::getFormattedItem($item ,$weightUnit, $showWeight);
396
+ }
397
+ }
398
+ if (self::$_debug) {
399
+ Mage::helper('wsalogger/log')->postDebug('ShipperHQ','Formatted Item List',$formattedItemList);
400
+ }
401
+
402
+ return $formattedItemList;
403
+ }
404
+
405
+
406
+ protected static function getFormattedItem($item, $weightUnit, $showWeight) {
407
+
408
+ $class = 'non_bundle';
409
+
410
+ if ($item->getHasChildren()) {
411
+ $class = 'bundle_parent';
412
+ } elseif ($item->getParentItemId()) {
413
+ $class = 'bundle_child';
414
+ }
415
+
416
+ $styleHtmlItem = self::getStyledHtmlItem(
417
+ $class,$item->getQty(),$item->getName(),$item->getWeight(), $weightUnit);
418
+
419
+ return $styleHtmlItem;
420
+ }
421
+
422
+ protected static function getStyledHtmlItem($itemType, $qty, $name,$weight,$weightUnit)
423
+ {
424
+ $weightHtmlDesc = $weightUnit == 'none' ? '' : '
425
+ <span class="'.$itemType.'_weight">'.round($weight).$weightUnit.'</span>';
426
+
427
+ $qtyHtmlDesc = '<span class="'.$itemType.'_qty">'.$qty.' x '.'</span>';
428
+
429
+ $nameHtmlDesc = '<span class="'.$itemType.'_name">'.$name.'</span>';
430
+
431
+ return $qtyHtmlDesc.$nameHtmlDesc.$weightHtmlDesc;
432
+
433
+ }
434
+
435
+ public function getCarrierGroupAddressShippingMethod($carrierGroup)
436
+ {
437
+ $shippingDetails = $this->getQuote()->getShippingAddress()->getCarriergroupShippingDetails();
438
+ if (empty($shippingDetails) || $shippingDetails=='') {
439
+ return;
440
+ }
441
+ $_cargrps = Mage::helper('shipperhq_shipper')->decodeShippingDetails($shippingDetails);
442
+ foreach ($_cargrps as $_cargrp) {
443
+ if (is_array($_cargrp) && $_cargrp['carrierGroupId']==$carrierGroup) {
444
+ return $_cargrp['code'];
445
+ }
446
+ }
447
+
448
+ }
449
+
450
+ public function showItemDescription()
451
+ {
452
+ $globals = Mage::helper('shipperhq_shipper')->getGlobalSettings();
453
+ $showDesc = $globals['dropshipShowItemDesc'];
454
+ return $showDesc;
455
+ }
456
+
457
+ public function getStorepickupHtml($carrierCode, $carrierType, $carriergroup = null )
458
+ {
459
+ return $this->_getStorePickup('storepickup_'.$carrierCode)
460
+ ->setCarriergroupId($carriergroup)
461
+ ->setCarrierCode($carrierCode)
462
+ ->setIsAccessPoints(Mage::helper('shipperhq_pickup')->isUpsAccessPointCarrier($carrierType))
463
+ ->setCarrierType($carrierType)
464
+ ->setName('storepickup_'.$carrierCode)
465
+ ->setTemplate($this->getStorePickUpBlockTemplate())
466
+ ->toHtml();
467
+ }
468
+
469
+ public function getCalendarHtml($carriergroup, $code, $soleMethod = false)
470
+ {
471
+
472
+ return $this->_getCalendar()
473
+ ->setCarriergroupId($carriergroup)
474
+ ->setCarrierCode($code)
475
+ ->setSoleMethod($soleMethod)
476
+ ->setName('calendar')
477
+ ->setTemplate($this->getCalendarBlockTemplate())
478
+ ->toHtml();
479
+ }
480
+
481
+ public function isPickupCarrier($rate)
482
+ {
483
+ if(!Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Pickup')) {
484
+ return false;
485
+ }
486
+ if($rate && Mage::helper('shipperhq_pickup')->isPickupEnabledCarrier($rate->getCarrierType())) {
487
+ if (self::$_debug) {
488
+ Mage::helper('wsalogger/log')->postDebug('ShipperHQ Pickup','Following carrier has pickup enabled: ',
489
+ 'Carrier: ' .$rate->getCode() .', Type : ' .$rate->getCarrierType() );
490
+ }
491
+ return true;
492
+ }
493
+ if (self::$_debug) {
494
+ Mage::helper('wsalogger/log')->postDebug('ShipperHQ Pickup','This carrier is not pickup enabled ',
495
+ 'Carrier: ' .$rate->getCode() .', Type : ' .$rate->getCarrierType());
496
+ }
497
+ return false;
498
+ }
499
+
500
+ public function isFreightCarrier($rate)
501
+ {
502
+ if(!Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Freight')) {
503
+ return false;
504
+ }
505
+ if($rate && $rate->getFreightRate() == 1) {
506
+ if (self::$_debug) {
507
+ Mage::helper('wsalogger/log')->postDebug('ShipperHQ Freight','Carrier is freight enabled',
508
+ 'Carrier : ' . $rate->getCode() .', Is freight rate : ' .$rate->getFreightRate()
509
+ );
510
+ }
511
+ return true;
512
+ }
513
+ if (self::$_debug) {
514
+ Mage::helper('wsalogger/log')->postDebug('ShipperHQ Freight','Carrier is NOT freight enabled',
515
+ 'Carrier : ' . $rate->getCode() .', Is freight rate : ' .$rate->getFreightRate()
516
+ );
517
+ }
518
+ return false;
519
+ }
520
+
521
+ public function getFreightAccessorialsHtml($carrierGroup, $carrierCode, $carrierType)
522
+ {
523
+ //go and get the freight accessorials and set them here for this one carrier
524
+
525
+ return $this->_getAccessorial('freight_'.$carrierCode)
526
+ ->setCarriergroupId($carrierGroup)
527
+ ->setCarrierCode($carrierCode)
528
+ ->setName('accessorial_'.$carrierCode)
529
+ ->setTemplate($this->getFreightAccessorialsBlockTemplate())
530
+ ->toHtml();
531
+ }
532
+
533
+ protected function _getStorePickup($name)
534
+ {
535
+ $this->_storepickup = $this->getLayout()->createBlock($this->getStorePickUpBlockType(), $name);
536
+ $this->_storepickup->setQuote($this->getQuote());
537
+ $this->_storepickup->setAddress($this->getAddress());
538
+ return $this->_storepickup;
539
+ }
540
+
541
+ protected function _getCalendar($name = '')
542
+ {
543
+ if (!$this->_calendar) {
544
+ $this->_calendar = $this->getLayout()->createBlock($this->getCalendarBlockType(), $name);
545
+ $this->_calendar->setQuote($this->getQuote());
546
+ $this->_calendar->setAddress($this->getAddress());
547
+ }
548
+
549
+ return $this->_calendar;
550
+ }
551
+
552
+ protected function _getAccessorial($name = '')
553
+ {
554
+ if (!$this->_accessorial) {
555
+ $this->_accessorial = $this->getLayout()->createBlock($this->getFreightAccessorialsBlockType(), $name);
556
+ $this->_accessorial->setQuote($this->getQuote());
557
+ $this->_accessorial->setAddress($this->getAddress());
558
+ }
559
+
560
+ return $this->_accessorial;
561
+ }
562
+
563
+ /**
564
+ * Returns a block type, that should be used for a calendar
565
+ *
566
+ * @return string
567
+ */
568
+ public function getStorePickUpBlockType()
569
+ {
570
+ return $this->_storePickupBlockType;
571
+ }
572
+
573
+ /**
574
+ * Sets store pickup block type
575
+ *
576
+ * @param $blockType
577
+ * @return $this
578
+ */
579
+ public function setStorePickUpBlockType($blockType)
580
+ {
581
+ $this->_storePickupBlockType = $blockType;
582
+ return $this;
583
+ }
584
+
585
+ /**
586
+ * Returns calendar block type
587
+ *
588
+ * @return string
589
+ */
590
+ public function getCalendarBlockType()
591
+ {
592
+ return $this->_calendarBlockType;
593
+ }
594
+
595
+ /**
596
+ * Sets calendar block type
597
+ *
598
+ * @param string $blockType
599
+ * @return $this
600
+ */
601
+ public function setCalendarBlockType($blockType)
602
+ {
603
+ $this->_calendarBlockType = $blockType;
604
+ return $this;
605
+ }
606
+
607
+ /**
608
+ * Returns a block type, that should be used for a calendar
609
+ *
610
+ * @return string
611
+ */
612
+ public function getStorePickUpBlockTemplate()
613
+ {
614
+ return $this->_storePickupBlockTemplate;
615
+ }
616
+
617
+ /**
618
+ * Sets store pickup block type
619
+ *
620
+ * @param string $template
621
+ * @return $this
622
+ */
623
+ public function setStorePickUpBlockTemplate($template)
624
+ {
625
+ $this->_storePickupBlockTemplate = $template;
626
+ return $this;
627
+ }
628
+
629
+ /**
630
+ * Returns calendar block type
631
+ *
632
+ * @return string
633
+ */
634
+ public function getCalendarBlockTemplate()
635
+ {
636
+ return $this->_calendarBlockTemplate;
637
+ }
638
+
639
+ /**
640
+ * Sets calendar block type
641
+ *
642
+ * @param string $blockType
643
+ * @return $this
644
+ */
645
+ public function setCalendarBlockTemplate($blockType)
646
+ {
647
+ $this->_calendarBlockTemplate = $blockType;
648
+ return $this;
649
+ }
650
+
651
+ /**
652
+ * @param mixed $freightAccessorialsBlockTemplate
653
+ */
654
+ public function setFreightAccessorialsBlockTemplate($freightAccessorialsBlockTemplate)
655
+ {
656
+ $this->_freightAccessorialsBlockTemplate = $freightAccessorialsBlockTemplate;
657
+ }
658
+
659
+ /**
660
+ * @return mixed
661
+ */
662
+ public function getFreightAccessorialsBlockTemplate()
663
+ {
664
+ return $this->_freightAccessorialsBlockTemplate;
665
+ }
666
+
667
+ /**
668
+ * @param string $freightAccessorialsBlockType
669
+ */
670
+ public function setFreightAccessorialsBlockType($freightAccessorialsBlockType)
671
+ {
672
+ $this->_freightAccessorialsBlockType = $freightAccessorialsBlockType;
673
+ }
674
+
675
+ /**
676
+ * @return string
677
+ */
678
+ public function getFreightAccessorialsBlockType()
679
+ {
680
+ return $this->_freightAccessorialsBlockType;
681
+ }
682
+
683
+
684
+
685
+ public function getCarrierName($carrierCode)
686
+ {
687
+ if ($name = Mage::getStoreConfig('carriers/'.$carrierCode.'/title', $this->getQuote()->getStoreId())) {
688
+ return $name;
689
+ }
690
+
691
+ return $carrierCode;
692
+ }
693
+
694
+ public function getAddressShippingMethod()
695
+ {
696
+ return $this->getAddress()->getShippingMethod();
697
+ }
698
+ }
app/code/community/Shipperhq/Frontend/Block/Checkout/Multishipping/Shipping.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Frontend_Block_Checkout_Multishipping_Shipping extends Mage_Checkout_Block_Multishipping_Shipping
32
+ {
33
+ private $_currentAddress;
34
+
35
+ public function setCurrentAddress($address){
36
+ $this->_currentAddress = $address;
37
+ }
38
+
39
+ public function getAddress()
40
+ {
41
+ return $this->_currentAddress;
42
+ }
43
+
44
+ public function getHelperBlock()
45
+ {
46
+ if ($this->_helperBlock === null) {
47
+ $this->_helperBlock = $this->getLayout()->createBlock(
48
+ 'shipperhq_frontend/checkout_helper',
49
+ sprintf('%s.helper', $this->getNameInLayout())
50
+ );
51
+
52
+ $this->_helperBlock->init(array(
53
+ 'calendar_block' => 'shipperhq_calendar/checkout_onepage_shipping_method_calendar',
54
+ 'calendar_template' => 'shipperhq/calendar/checkout/onepage/shipping_method/calendar.phtml',
55
+ 'pickup_block' => 'shipperhq_pickup/checkout_onepage_shipping_method_storepickup',
56
+ 'pickup_template' => 'shipperhq/pickup/checkout/onepage/shipping_method/storepickup.phtml',
57
+ 'quote' => $this->getCheckout()->getQuote(),
58
+ 'address' => $this->getAddress()
59
+ ));
60
+ }
61
+
62
+
63
+ return $this->_helperBlock;
64
+ }
65
+
66
+ public function getCalendarHtml($carriergroup, $code)
67
+ {
68
+ return $this->getHelperBlock()->getCalendarHtml($carriergroup, $code);
69
+ }
70
+
71
+ public function getStorepickupHtml($carrierCode, $carrierType, $carriergroup = null)
72
+ {
73
+ return $this->getHelperBlock()->getStorepickupHtml($carrierCode, $carrierType, $carriergroup);
74
+ }
75
+
76
+ public function getCarrierGroupRates($address)
77
+ {
78
+ $this->getHelperBlock()->setAddress($address);
79
+ return $this->getHelperBlock()->getCarrierGroupRates();
80
+ }
81
+
82
+ public function getAddressItemsGrouped($address, $cg_items, $carrierGroupId)
83
+ {
84
+ $items = array();
85
+ foreach ($address->getAllItems() as $item) {
86
+ if ($item->getParentItemId()) {
87
+ continue;
88
+ }
89
+ $item->setQuoteItem($this->getCheckout()->getQuote()->getItemById($item->getQuoteItemId()));
90
+ if((int)$carrierGroupId == 0 ) {
91
+ $items[] = $item;
92
+ }
93
+ else {
94
+ foreach($cg_items as $cgitem) {
95
+ if($cgitem->getQuoteItemId() == $item->getQuoteItemId()) {
96
+ $items[] = $item;
97
+ }
98
+ }
99
+ }
100
+ }
101
+ $itemsFilter = new Varien_Filter_Object_Grid();
102
+ $itemsFilter->addFilter(new Varien_Filter_Sprintf('%d'), 'qty');
103
+ return $itemsFilter->filter($items);
104
+ }
105
+
106
+ public function getPickupAddress()
107
+ {
108
+ return Mage::helper('shipperhq_pickup')->__('In Store Pickup');
109
+ }
110
+
111
+ public function isPickupCarrier($rate)
112
+ {
113
+ return $this->getHelperBlock()->isPickupCarrier($rate);
114
+ }
115
+
116
+ public function getMethodTitle($methodTitle, $methodDescription, $includeContainer)
117
+ {
118
+ return $this->getHelperBlock()->getMethodTitle($methodTitle, $methodDescription, $includeContainer);
119
+ }
120
+
121
+ }
122
+
app/code/community/Shipperhq/Frontend/Block/Checkout/Onepage/Progress.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Provides proxy methods for helper block
33
+ *
34
+ * Supplies helper block with render information
35
+ */
36
+ class Shipperhq_Frontend_Block_Checkout_Onepage_Progress extends Mage_Checkout_Block_Onepage_Progress
37
+ {
38
+
39
+ public function getShippingDescription()
40
+ {
41
+ $shipDescrption = $this->getQuote()->getShippingAddress()->getShippingDescription();
42
+ if($this->getQuote()->getShippingAddress()->getDeliveryDate()) {
43
+ $shipDescrption.= ' (Delivery date: ' .$this->getQuote()->getShippingAddress()->getDeliveryDate();
44
+ if($this->getQuote()->getShippingAddress()->getTimeSlot() != '') {
45
+ $shipDescrption.= ' ' .$this->getQuote()->getShippingAddress()->getTimeSlot();
46
+ }
47
+ $shipDescrption.= ')';
48
+
49
+ }
50
+ return $shipDescrption;
51
+ }
52
+ }
app/code/community/Shipperhq/Frontend/Block/Checkout/Onepage/Shipping/Method/Available.php ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Provides proxy methods for helper block
33
+ *
34
+ * Supplies helper block with render information
35
+ */
36
+ class Shipperhq_Frontend_Block_Checkout_Onepage_Shipping_Method_Available extends Mage_Checkout_Block_Onepage_Shipping_Method_Available
37
+ {
38
+ /**
39
+ * Returns a helper block, that is used to retrieve all data
40
+ *
41
+ * @return Shipperhq_Frontend_Block_Checkout_Helper
42
+ */
43
+ public function getHelperBlock()
44
+ {
45
+ if ($this->_helperBlock === null) {
46
+ $this->_helperBlock = $this->getLayout()->createBlock(
47
+ 'shipperhq_frontend/checkout_helper',
48
+ sprintf('%s.helper', $this->getNameInLayout())
49
+ );
50
+
51
+ $this->_helperBlock->init(array(
52
+ 'calendar_block' => 'shipperhq_calendar/checkout_onepage_shipping_method_calendar',
53
+ 'calendar_template' => 'shipperhq/calendar/checkout/onepage/shipping_method/calendar.phtml',
54
+ 'pickup_block' => 'shipperhq_pickup/checkout_onepage_shipping_method_storepickup',
55
+ 'pickup_template' => 'shipperhq/pickup/checkout/onepage/shipping_method/storepickup.phtml',
56
+ 'accessorials_block' => 'shipperhq_freight/checkout_onepage_shipping_method_accessorials',
57
+ 'accessorials_template' => 'shipperhq/freight/checkout/onepage/shipping_method/accessorials.phtml',
58
+ 'quote' => $this->getQuote(),
59
+ 'address' => $this->getAddress()
60
+ ));
61
+ }
62
+
63
+
64
+ return $this->_helperBlock;
65
+ }
66
+
67
+ public function getCarrierGroupRates()
68
+ {
69
+ return $this->getHelperBlock()->getCarrierGroupRates();
70
+ }
71
+
72
+ public function getProcessedShippingRates()
73
+ {
74
+ return $this->getHelperBlock()->getProcessedShippingRates($this->getShippingRates());
75
+ }
76
+
77
+ /*
78
+ * Retrieves the items details ready for printing to checkout when < 2 carrier groups are in checkout
79
+ */
80
+ public function getSingleItemDetails($shippingRates)
81
+ {
82
+ return $this->getHelperBlock()->getSingleItemDetails($shippingRates);
83
+ }
84
+
85
+ /**
86
+ * Populates the location select dropdown
87
+ * @return string
88
+ */
89
+ public function getShippingMethodsSelect($name, $id, $value, $rates, $sole)
90
+ {
91
+ return $this->getHelperBlock()->getShippingMethodsSelect($name, $id, $value, $rates, $sole);
92
+ }
93
+
94
+
95
+ public function isShippingMethodSelected($rates)
96
+ {
97
+ return $this->getHelperBlock()->isShippingMethodSelected($rates);
98
+ }
99
+
100
+ public function getMethodTitle($methodTitle, $methodDescription, $includeContainer)
101
+ {
102
+ return $this->getHelperBlock()->getMethodTitle($methodTitle, $methodDescription, $includeContainer);
103
+ }
104
+
105
+ public function getShippingPrice($price, $flag, $includeContainer = true)
106
+ {
107
+ return $this->getHelperBlock()->getShippingPrice($price, $flag, $includeContainer);
108
+ }
109
+
110
+ public function showToolTips() {
111
+ return $this->getHelperBlock()->showToolTips();
112
+ }
113
+
114
+ public function getToolTipText()
115
+ {
116
+ return $this->getHelperBlock()->getToolTipText();
117
+ }
118
+
119
+ protected function getFormattedItemList($items)
120
+ {
121
+ return $this->getHelperBlock()->getFormattedItemList($items);
122
+ }
123
+
124
+ public function getCarrierGroupAddressShippingMethod($carrierGroup)
125
+ {
126
+ return $this->getHelperBlock()->getCarrierGroupAddressShippingMethod($carrierGroup);
127
+ }
128
+
129
+ public function showItemDescription()
130
+ {
131
+ return $this->getHelperBlock()->showItemDescription();
132
+ }
133
+
134
+ public function getStorepickupHtml($carrierCode, $carrierType, $carriergroup = null )
135
+ {
136
+ return $this->getHelperBlock()->getStorepickupHtml($carrierCode, $carrierType, $carriergroup);
137
+ }
138
+
139
+ public function getCalendarHtml($carriergroup, $code, $soleMethod = false)
140
+ {
141
+ return $this->getHelperBlock()->getCalendarHtml($carriergroup, $code, $soleMethod);
142
+ }
143
+
144
+ public function isPickupCarrier($rate)
145
+ {
146
+ return $this->getHelperBlock()->isPickupCarrier($rate);
147
+ }
148
+
149
+ public function isFreightCarrier($rate)
150
+ {
151
+ return $this->getHelperBlock()->isFreightCarrier($rate);
152
+ }
153
+
154
+ public function getFreightAccessorialsHtml($carrierCode, $carrierType, $carrerigroup = '')
155
+ {
156
+ return $this->getHelperBlock()->getFreightAccessorialsHtml($carrerigroup, $carrierCode, $carrierType);
157
+ }
158
+ }
app/code/community/Shipperhq/Frontend/Model/Checkout/Type/Multishipping.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Frontend_Model_Checkout_Type_Multishipping extends Mage_Checkout_Model_Type_Multishipping
32
+ {
33
+
34
+ /**
35
+ * Set payment method info to quote payment
36
+ *
37
+ * @param array $payment
38
+ * @return Mage_Checkout_Model_Type_Multishipping
39
+ */
40
+ public function setPaymentMethod($payment)
41
+ {
42
+ if (!isset($payment['method'])) {
43
+ Mage::throwException(Mage::helper('checkout')->__('Payment method is not defined'));
44
+ }
45
+ $quote = $this->getQuote();
46
+ $quote->getPayment()->importData($payment);
47
+
48
+ // shipping totals may be affected by payment method
49
+ if (!$quote->isVirtual() && $quote->getShippingAddress()) {
50
+ // $quote->getShippingAddress()->setCollectShippingRates(true);
51
+ $quote->setTotalsCollectedFlag(false)->collectTotals();
52
+ }
53
+ $quote->save();
54
+ return $this;
55
+ }
56
+
57
+ /**
58
+ * Prepare order based on quote address
59
+ *
60
+ * @param Mage_Sales_Model_Quote_Address $address
61
+ * @return Mage_Sales_Model_Order
62
+ * @throws Mage_Checkout_Exception
63
+ */
64
+ protected function _prepareOrder(Mage_Sales_Model_Quote_Address $address)
65
+ {
66
+ $quote = $this->getQuote();
67
+ $quote->unsReservedOrderId();
68
+ $quote->reserveOrderId();
69
+ $quote->collectTotals();
70
+
71
+ $convertQuote = Mage::getSingleton('sales/convert_quote');
72
+ $order = $convertQuote->addressToOrder($address);
73
+ $order->setQuote($quote);
74
+ $order->setBillingAddress(
75
+ $convertQuote->addressToOrderAddress($quote->getBillingAddress())
76
+ );
77
+
78
+ if ($address->getAddressType() == 'billing') {
79
+ $order->setIsVirtual(1);
80
+ } else {
81
+ $order->setShippingAddress($convertQuote->addressToOrderAddress($address));
82
+ }
83
+
84
+ $order->setPayment($convertQuote->paymentToOrderPayment($quote->getPayment()));
85
+ if (Mage::app()->getStore()->roundPrice($address->getGrandTotal()) == 0) {
86
+ $order->getPayment()->setMethod('free');
87
+ }
88
+
89
+ foreach ($address->getAllItems() as $item) {
90
+ $_quoteItem = $item->getQuoteItem();
91
+ if (!$_quoteItem) {
92
+ throw new Mage_Checkout_Exception(Mage::helper('checkout')->__('Item not found or already ordered'));
93
+ }
94
+ $item->setProductType($_quoteItem->getProductType())
95
+ ->setProductOptions(
96
+ $_quoteItem->getProduct()->getTypeInstance(true)->getOrderOptions($_quoteItem->getProduct())
97
+ );
98
+ // $item->setCarriergroupId($_quoteItem->getCarriergroupId());
99
+ // $item->setCarriergroup($_quoteItem->getCarriergroup());
100
+ $orderItem = $convertQuote->itemToOrderItem($item);
101
+ if ($item->getParentItem()) {
102
+ $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
103
+ }
104
+ $order->addItem($orderItem);
105
+ }
106
+
107
+ return $order;
108
+ }
109
+
110
+ /**
111
+ * Add quote item to specific shipping address based on customer address id
112
+ *
113
+ * @param int $quoteItemId
114
+ * @param array $data array('qty'=>$qty, 'address'=>$customerAddressId)
115
+ * @return Mage_Checkout_Model_Type_Multishipping
116
+ */
117
+ protected function _addShippingItem($quoteItemId, $data)
118
+ {
119
+ if(!Mage::helper('shipperhq_pickup')->preselectPickupEnabled()) {
120
+ return parent::_addShippingItem($quoteItemId, $data);
121
+ }
122
+
123
+ $qty = isset($data['qty']) ? (int) $data['qty'] : 1;
124
+ //$qty = $qty > 0 ? $qty : 1;
125
+ $addressId = isset($data['address']) ? $data['address'] : false;
126
+ $quoteItem = $this->getQuote()->getItemById($quoteItemId);
127
+
128
+ if ($addressId && $quoteItem) {
129
+ /**
130
+ * Skip item processing if qty 0
131
+ */
132
+ if ($qty === 0) {
133
+ return $this;
134
+ }
135
+ $quoteItem->setMultishippingQty((int)$quoteItem->getMultishippingQty()+$qty);
136
+ $quoteItem->setQty($quoteItem->getMultishippingQty());
137
+ $preselectedPickupAddressId = Mage::helper('shipperhq_pickup')->getPreselectPickupAddressId();
138
+ if(strstr($addressId, $preselectedPickupAddressId)) {
139
+ $address = $this->getCustomer()->getDefaultBillingAddress();
140
+ } else {
141
+ $address = $this->getCustomer()->getAddressById($addressId);
142
+ }
143
+ if ($address->getId()) {
144
+ if(strstr($addressId, $preselectedPickupAddressId)) {
145
+ if($this->_storePickupAddressId == false) {
146
+ $quoteAddress = Mage::getModel('sales/quote_address')->importCustomerAddress($address);
147
+ $quoteAddress->setCustomerAddressId($addressId);
148
+ $this->_storePickupAddressId = true;
149
+ $this->getQuote()->addShippingAddress($quoteAddress);
150
+ }
151
+ }
152
+ elseif (!$quoteAddress = $this->getQuote()->getShippingAddressByCustomerAddressId($address->getId())) {
153
+ $quoteAddress = Mage::getModel('sales/quote_address')->importCustomerAddress($address);
154
+ $this->getQuote()->addShippingAddress($quoteAddress);
155
+ }
156
+ if(strstr($addressId, $preselectedPickupAddressId)) {
157
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
158
+ Mage::helper('wsalogger/log')->postInfo('ShipperHQ Pickup', 'Creating separate address for store pickup item',
159
+ $quoteItem->getSku());
160
+ }
161
+ $quoteAddress = $this->getQuote()->getShippingAddressByCustomerAddressId($addressId);
162
+ $quoteAddress->setPickupPreselected(true);
163
+ }
164
+ else {
165
+ $quoteAddress = $this->getQuote()->getShippingAddressByCustomerAddressId($address->getId());
166
+ }
167
+ if ($quoteAddressItem = $quoteAddress->getItemByQuoteItemId($quoteItemId)) {
168
+ $quoteAddressItem->setQty((int)($quoteAddressItem->getQty()+$qty));
169
+ } else {
170
+ $quoteAddress->addItem($quoteItem, $qty);
171
+ }
172
+
173
+ /**
174
+ * Require shiping rate recollect
175
+ */
176
+ $quoteAddress->setCollectShippingRates((boolean) $this->getCollectRatesFlag());
177
+ }
178
+ }
179
+ return $this;
180
+ }
181
+ }
app/code/community/Shipperhq/Frontend/etc/config.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <global>
3
+ <blocks>
4
+ <shipperhq_frontend>
5
+ <class>Shipperhq_Frontend_Block</class>
6
+ </shipperhq_frontend>
7
+ </blocks>
8
+ </global>
9
+ </config>
app/code/community/Shipperhq/Migration/Block/Adminhtml/Migration.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+ //Mage_Adminhtml_Block_Template
31
+ class Shipperhq_Migration_Block_Adminhtml_Migration extends Mage_Adminhtml_Block_Widget_Form_Container
32
+ {
33
+
34
+ public function __construct()
35
+ {
36
+ $this->_controller = 'adminhtml_migration';
37
+ $this->_blockGroup = 'shipperhq_migration';
38
+ $this->_headerText = Mage::helper('shipperhq_shipper')->__('Migration Manager');
39
+
40
+
41
+ parent::__construct();
42
+ $this->removeButton('back')
43
+ ->removeButton('reset')
44
+ ->removeButton('save');
45
+
46
+ }
47
+
48
+ }
app/code/community/Shipperhq/Migration/Block/Adminhtml/Migration/Edit/Form.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+
32
+ class Shipperhq_Migration_Block_Adminhtml_Migration_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
33
+ {
34
+
35
+ }
app/code/community/Shipperhq/Migration/Block/Adminhtml/Migration/Migratable.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+
32
+ class Shipperhq_Migration_Block_Adminhtml_Migration_Migratable extends Mage_Adminhtml_Block_Widget_Form
33
+ {
34
+ public function __construct($attributes=array())
35
+ {
36
+ parent::__construct($attributes);
37
+ $this->setTemplate('shipperhq/migrate_extension.phtml');
38
+
39
+ }
40
+
41
+ public function getHelperText()
42
+ {
43
+ $data = $this->getExtension();
44
+ if(is_array($data) && array_key_exists('helper', $data)) {
45
+ return $data['helper'];
46
+ }
47
+ }
48
+
49
+ public function getAttributes()
50
+ {
51
+ $data = $this->getExtension();
52
+ $arrayOfData = array();
53
+ if(is_array($data) && array_key_exists('attributes', $data)) {
54
+ $arrayOfData = $data['attributes'];
55
+ if(!is_array($arrayOfData)) {
56
+ $arrayOfData = $arrayOfData->asArray();
57
+ }
58
+ }
59
+ return $arrayOfData;
60
+
61
+ }
62
+
63
+ public function getTableHtml($attributeConfig, $store)
64
+ {
65
+ $fromAttributeCode = $attributeConfig['from']['code'];
66
+ $toAttributeCode = $attributeConfig['to']['code'];
67
+ $toType = $attributeConfig['to']['type'];
68
+ $html = '<div class="grid"><table id="'. $attributeConfig['from']['code'] .'" class="migration">';
69
+
70
+ switch($attributeConfig['type']) {
71
+ case 'select': {
72
+ $html.= '<thead><tr class="headings">
73
+ <th>Products with '.$attributeConfig['from']['title'] .' value of</th>
74
+ <th class="last">Assigned ' .$attributeConfig['to']['title']. ' value of</th>
75
+ </tr>
76
+ </thead><tbody>';
77
+ $html.= $this->getSelectTableHtml($attributeConfig, $store);
78
+ $buttonOnClick = 'migrateSelectClick';
79
+ break;
80
+ }
81
+ case 'textselect': {
82
+ $html.= '<thead><tr class="headings">
83
+ <th>Products with '.$attributeConfig['from']['title'] .' enabled</th>
84
+ <th class="last">Assigned ' .$attributeConfig['to']['title']. ' value of</th>
85
+ </tr>
86
+ </thead><tbody>';
87
+ $html.= $this->getTextSelectTableHtml($attributeConfig, $store);
88
+ $buttonOnClick = 'migrateSelectClick';
89
+ break;
90
+ }
91
+ default: {
92
+ $html.= '<thead><tr class="headings"><th>Values Copied From Here</th>
93
+ <th class="last">Into Here</th>
94
+ </tr>
95
+ </thead><tbody>
96
+ <tr>
97
+ <td class="label">'.$attributeConfig['from']['title'] .'</td>
98
+ <td class="label">' .$attributeConfig['to']['title']. '</td>
99
+ </tr>';
100
+ $buttonOnClick = 'migrateDefaultClick';
101
+ }
102
+ }
103
+ $html .='</tbody></table></div>';
104
+ $button = $this->getButtonHtml('Migrate', "{$buttonOnClick}('{$fromAttributeCode}', '{$toAttributeCode}', '{$toType}')", '', $fromAttributeCode.'_button');
105
+ $display = '<div><span id="' .$fromAttributeCode .'_output_result" class="no-display"></span></div><br/>';
106
+ $html.= $button .$display;
107
+ return $html;
108
+ }
109
+
110
+ public function getSelectTableHtml($attributeConfig, $store = null)
111
+ {
112
+ $fromAttributeCode = $attributeConfig['from']['code'];
113
+ $existingAttributeValues = Mage::helper('shipperhq_migration')->getAllAttributeValues($fromAttributeCode, $store);
114
+ $newAttributeValues = Mage::helper('shipperhq_migration')->getAllAttributeValues($attributeConfig['to']['code'], $store);
115
+ $html = '';
116
+ if(is_array($existingAttributeValues) && count($existingAttributeValues) > 0) {
117
+
118
+ foreach($existingAttributeValues as $value => $name)
119
+ {
120
+ if(count($newAttributeValues) < 1) {
121
+ $newValuesSelect = $this->getErrorNoValues($attributeConfig['to']['code']);
122
+ }
123
+ else {
124
+ $newValuesSelect = $this->getSelect($fromAttributeCode.'_'.$value, $newAttributeValues);
125
+ }
126
+ if($value == '') continue;
127
+ $rowHtml = '<tr class="even pointer" title="#">
128
+ <td class="a-left ">'
129
+ .$name.'</td>
130
+ <td class="a-left last">'. $newValuesSelect .'</td></tr>';
131
+
132
+ $html.=$rowHtml;
133
+ }
134
+
135
+
136
+ }
137
+ else {
138
+ $notice = '<span class="notice"><span>'
139
+ .$this->__('No existing attribute values, nothing to migrate.').'</span></span>';
140
+
141
+ $html .= '<tr class="even pointer" title="#">
142
+ <td class="a-left ">'
143
+ .$notice.'</td>
144
+ <td class="a-left last"></td></tr>';
145
+ }
146
+
147
+ return $html;
148
+ }
149
+
150
+ public function getTextSelectTableHtml($attributeConfig, $store)
151
+ {
152
+ $fromAttributeCode = $attributeConfig['from']['code'];
153
+ $existingAttributeValues = Mage::helper('shipperhq_migration')->getBooleanValues();
154
+ $newAttributeValues = Mage::helper('shipperhq_migration')->getAllAttributeValues($attributeConfig['to']['code'], $store);
155
+ $html = '';
156
+ if(is_array($existingAttributeValues) && count($existingAttributeValues) > 0) {
157
+
158
+ foreach($existingAttributeValues as $value => $name)
159
+ {
160
+ if(count($newAttributeValues) < 1) {
161
+ $newValuesSelect = $this->getErrorNoValues($attributeConfig['to']['code']);
162
+ }
163
+ else {
164
+ $newValuesSelect = $this->getSelect($fromAttributeCode.'_'.$value, $newAttributeValues);
165
+ }
166
+ if($value == '') continue;
167
+ $rowHtml = '<tr class="even pointer" title="#">
168
+ <td class="a-left ">'
169
+ .$name.'</td>
170
+ <td class="a-left last">'. $newValuesSelect .'</td></tr>';
171
+
172
+ $html.=$rowHtml;
173
+ }
174
+
175
+
176
+ }
177
+ else {
178
+ $notice = '<span class="notice"><span>'
179
+ .$this->__('No existing attribute values, nothing to migrate.').'</span></span>';
180
+
181
+ $html .= '<tr class="even pointer" title="#">
182
+ <td class="a-left ">'
183
+ .$notice.'</td>
184
+ <td class="a-left last"></td></tr>';
185
+ }
186
+
187
+ return $html;
188
+ }
189
+
190
+ public function getSelect($id, $values)
191
+ {
192
+ $values[''] = Mage::helper('shipperhq_migration')->__('Select a value');
193
+ ksort($values);
194
+ $select = $this->getLayout()->createBlock('adminhtml/html_select')
195
+ ->setData(array(
196
+ 'id' => $id,
197
+ 'class' => 'select select-product-option-type'
198
+ ))
199
+ ->setName($id)
200
+ ->setOptions($values);
201
+
202
+ return $select->getHtml();
203
+ }
204
+
205
+ public function getErrorNoValues($toAttribute)
206
+ {
207
+ $notice = '<span class="error">'
208
+ .$this->__('No values for '. $toAttribute .' attribute. Please configure in ShipperHQ Dashboard then synchronize')
209
+ .'</span>';
210
+ return $notice;
211
+
212
+ }
213
+
214
+ }
app/code/community/Shipperhq/Migration/Helper/Data.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Shipping data helper
33
+ */
34
+ class Shipperhq_Migration_Helper_Data extends Mage_Core_Helper_Abstract
35
+ {
36
+ /**
37
+ * @var array
38
+ */
39
+ protected $_complexTypes = array('multiselect', 'select');
40
+ /**
41
+ * @var null
42
+ */
43
+ protected $_migrateConfig = null;
44
+
45
+ /**
46
+ * Parse xml to attribute migration configuration
47
+ * @return array
48
+ */
49
+ public function getAttributesToMigrate()
50
+ {
51
+ $config = $this->getMigrationConfig();
52
+ $attributeConfig = $config->getNode('modules');
53
+ $migrate = array();
54
+ foreach ($attributeConfig->children() as $attribute) {
55
+ $configArray = $this->verifyAttributes((array)$attribute);
56
+
57
+ if($configArray) {
58
+ $migrate[] = $configArray;
59
+ }
60
+ }
61
+ return $migrate;
62
+ }
63
+
64
+ /**
65
+ * Retrieve XML configuration from file
66
+ * @return Mage_Core_Model_Config_Base|null
67
+ */
68
+ public function getMigrationConfig()
69
+ {
70
+ if (is_null($this->_migrateConfig)) {
71
+ $migrationConfig = new Varien_Simplexml_Config;
72
+ $migrationConfig->loadString('<?xml version="1.0"?><shipperhq_migrate></shipperhq_migrate>');
73
+ $migrationConfig = Mage::getConfig()->loadModulesConfiguration('migrate.xml');
74
+ $this->_migrateConfig = $migrationConfig;
75
+ }
76
+ return $this->_migrateConfig;
77
+
78
+ }
79
+
80
+ /**
81
+ * Retrieve all possible attribute values for selectable attribute types
82
+ * @param $attribute_code
83
+ * @param null $store
84
+ * @return array
85
+ */
86
+ public function getAllAttributeValues($attribute_code, $store = null)
87
+ {
88
+ $attribute = $this->getAttribute($attribute_code, $store);
89
+ $source = $attribute->getSource();
90
+ $options = array();
91
+ foreach($source->getAllOptions(false) as $option)
92
+ {
93
+ $options[$option['value']] = $option['label'];
94
+ }
95
+
96
+ return $options;
97
+ }
98
+
99
+ public function getBooleanValues()
100
+ {
101
+ return array(1 => "YES");
102
+ }
103
+
104
+ /**
105
+ * Verify configured attributes are installed
106
+ * @param $configArray
107
+ * @return mixed
108
+ */
109
+ protected function verifyAttributes($configArray)
110
+ {
111
+ $configArray['attributes'] = $configArray['attributes']->asArray();
112
+ $module = $configArray['module'];
113
+ if(!Mage::helper('shipperhq_shipper')->isModuleEnabled($module)) {
114
+ return false;
115
+ }
116
+ foreach($configArray['attributes'] as $attribute_code => $config)
117
+ {
118
+ if(!$this->getAttribute($attribute_code)) {
119
+ unset($configArray['attributes'][$attribute_code]);
120
+ continue;
121
+ }
122
+
123
+ }
124
+
125
+ if(empty($configArray['attributes'])) {
126
+ return false;
127
+ }
128
+ return $configArray;
129
+ }
130
+
131
+ /**
132
+ * Retrieve attribute catalog product attribute
133
+ * @param $attribute_code
134
+ * @param null $store
135
+ * @return mixed
136
+ */
137
+ protected function getAttribute($attribute_code, $store = null) {
138
+ $attribute = Mage::getResourceModel('catalog/product')
139
+ ->getAttribute($attribute_code);
140
+
141
+ if(is_null($store) || $store == '') {
142
+ $store = Mage_Core_Model_App::ADMIN_STORE_ID;
143
+ }
144
+ if($attribute) {
145
+ $attribute->setStoreId($store);
146
+
147
+ return $attribute;
148
+ }
149
+ return false;
150
+ }
151
+
152
+ }
app/code/community/Shipperhq/Migration/Model/Migrate.php ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ *
30
+ * ST_Core_Model_Resource_Iterator_Batched : Kalen Jordan
31
+ */
32
+ class Shipperhq_Migration_Model_Migrate extends Mage_Core_Model_Abstract
33
+ {
34
+
35
+ const BATCH_SIZE = 100;
36
+ /**
37
+ * Assign values from one attribute to another - for text or numeric attribute types, uses callback function below
38
+ * @param $oldAttributeCode
39
+ * @param $newAttributeCode
40
+ * @return int
41
+ */
42
+ public function copyAttributeValues($oldAttributeCode, $newAttributeCode, $storeId)
43
+ {
44
+ $collection = Mage::getModel('catalog/product')->setStoreId($storeId)->getCollection();
45
+ $collection->addAttributeToSelect($oldAttributeCode);
46
+ if($storeId == '') {
47
+ $storeId = 0;
48
+ }
49
+ if($storeId != '') {
50
+ $collection->addStoreFilter((int)$storeId);
51
+ }
52
+ $collection->addFieldToFilter(array(
53
+ array('attribute'=>$oldAttributeCode,'neq'=>''),
54
+ ));
55
+
56
+ $collection->setPageSize(self::BATCH_SIZE);
57
+ if($collection) {
58
+ try {
59
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
60
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq Migration', 'Migration about to begin for',
61
+ ' products to copy value for ' .$oldAttributeCode);
62
+ }
63
+
64
+ $args = array('old_attribute'=> $oldAttributeCode, 'new_attribute'=> $newAttributeCode,
65
+ 'store_id' => $storeId);
66
+ $batcher = Mage::getSingleton('shipperhq_migration/resource_iterator_batched');
67
+ $result = $batcher->walk(
68
+ $collection,
69
+ array($this, 'copyAttributeCallback'),
70
+ $args,
71
+ array($this, 'copyAttributeBatchCallback')
72
+ );
73
+ }
74
+ catch(Exception $e){
75
+ Mage::logException("ShipperHQ Migration Exception");
76
+ Mage::logException($e);
77
+ return -1;
78
+ }
79
+ }
80
+ else {
81
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
82
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq Migration', 'No migration required',
83
+ 'No products for ' .$oldAttributeCode);
84
+ }
85
+ }
86
+ return $result;
87
+ }
88
+
89
+ /**
90
+ * Callback function to copy attribute values
91
+ * @param $args
92
+ */
93
+ public function copyAttributeCallback($args)
94
+ {
95
+ $product = $args[0];
96
+ $data = $args[1];
97
+ $oldAttributeCode = $data['old_attribute'];
98
+ $newAttributeCode = $data['new_attribute'];
99
+ $valueToCopy = $product[$oldAttributeCode];
100
+ $productArray = array($product->getId());
101
+ $attData = array($newAttributeCode => $valueToCopy);
102
+
103
+ Mage::getResourceSingleton('catalog/product_action')
104
+ ->updateAttributes($productArray, $attData, $data['store_id']);
105
+ }
106
+
107
+ public function copyAttributeBatchCallback($args)
108
+ {
109
+ $currentPage = (int)$args['current_page'];
110
+ $totalPages = (int)$args['total_pages'];
111
+
112
+ $percentage = number_format(($currentPage/$totalPages)*100,2);
113
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
114
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq Migration', 'Current migration task', $currentPage
115
+ .' of ' .$totalPages .' pages of products processed, ' .$percentage .'% Complete');
116
+ }
117
+ }
118
+
119
+ public function migrateAttributeValues($processThese, $attributeCode, $toAttributeCode, $storeId, $attributeToType)
120
+ {
121
+
122
+ $numberProcessed = 0;
123
+ if($storeId == '') {
124
+ $storeId = 0;
125
+ }
126
+ if(!empty($processThese)) {
127
+ //suspend indexing for the time being
128
+ // $this->unSetIndex();
129
+ foreach($processThese as $attributeCode => $valuesToMigrate) {
130
+ foreach($valuesToMigrate as $oldValue => $newValue) {
131
+ if($newValue != '') {
132
+ $result = $this->setAttributeValue($attributeCode, $oldValue, $toAttributeCode, $newValue, $storeId, $attributeToType);
133
+ if($result < 0) {
134
+ $result = Mage::helper('shipperhq_migration')->__(
135
+ 'There was an error saving new attribute values');
136
+ }
137
+ else {
138
+ $numberProcessed+= $result;
139
+ }
140
+ }
141
+ }
142
+
143
+ }
144
+ //reinstate indexing
145
+ // $this->setIndex();
146
+ }
147
+ return $numberProcessed;
148
+
149
+ }
150
+
151
+ /**
152
+ * Update array of products' attribute with new value
153
+ * @param $productArray - array of product IDs
154
+ * @param $attribute_code
155
+ * @param $value
156
+ * @return int
157
+ */
158
+ public function setAttributeValue($from_attribute_code, $oldValue, $to_attribute_code, $value, $storeId, $attributeToType)
159
+ {
160
+ $productCollection = Mage::getModel('catalog/product')->setStoreId($storeId)->getCollection();
161
+ if(!is_null($storeId) && $storeId != '') {
162
+ $productCollection->addStoreFilter((int)$storeId);
163
+ }
164
+
165
+ $productCollection->addAttributeToSelect($from_attribute_code);
166
+ $productCollection->addFieldToFilter(array(
167
+ array('attribute'=>$from_attribute_code,'finset'=>$oldValue),
168
+ ));
169
+ $productCollection->setPageSize(self::BATCH_SIZE);
170
+ if($productCollection) {
171
+ try {
172
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
173
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq Migration', 'Migration about to begin for',
174
+ ' products with ' .$from_attribute_code .' attribute value of ' .$oldValue);
175
+ }
176
+ $args = array('values' => array($to_attribute_code => $value),
177
+ 'store_id' => $storeId, 'attribute_to_type' => $attributeToType);
178
+ $batcher = Mage::getSingleton('shipperhq_migration/resource_iterator_batched');
179
+ $result = $batcher->walk(
180
+ $productCollection,
181
+ array($this, 'setAttributeValueCallback'),
182
+ $args,
183
+ array($this, 'setAttributeValueBatchCallback')
184
+ );
185
+
186
+ }
187
+ catch(Exception $e){
188
+ Mage::logException("ShipperHQ Migration Exception");
189
+ Mage::logException($e);
190
+ return -1;
191
+ }
192
+ }
193
+ else {
194
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
195
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq Migration', 'No migration required',
196
+ 'No products with ' .$from_attribute_code .' attribute value of ' .$oldValue);
197
+ }
198
+ }
199
+ return $result;
200
+
201
+ }
202
+
203
+ /**
204
+ * Callback function to set attribute value
205
+ * @param $args
206
+ */
207
+ public function setAttributeValueCallback($args)
208
+ {
209
+ $product = $args[0];
210
+ $data = $args[1];
211
+ $productArray = array($product->getId());
212
+ $isMultiSelect = $data['attribute_to_type'] == 'multiselect';
213
+ if($isMultiSelect) {
214
+ Mage::getSingleton('shipperhq_migration/product_action')
215
+ ->updateAttributes($productArray, $data['values'], $data['store_id']);
216
+ }
217
+ else {
218
+ Mage::getResourceSingleton('catalog/product_action')
219
+ ->updateAttributes($productArray, $data['values'], $data['store_id']);
220
+ }
221
+
222
+ }
223
+
224
+ public function setAttributeValueBatchCallback($args)
225
+ {
226
+ $currentPage = (int)$args['current_page'];
227
+ $totalPages = (int)$args['total_pages'];
228
+
229
+ $percentage = number_format(($currentPage/$totalPages)*100,2);
230
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
231
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq Migration', 'Current migration task', $currentPage
232
+ .' of ' .$totalPages .' pages of products processed, ' .$percentage .'% Complete');
233
+ }
234
+ }
235
+
236
+ /**
237
+ * Retrieve option id for given attribute value
238
+ * @param $attribute
239
+ * @param $value
240
+ * @return mixed
241
+ */
242
+ protected function _getOptionId($attribute, $value)
243
+ {
244
+ //get the source
245
+ $source = $attribute->getSource();
246
+
247
+ //get the id
248
+ $id = $source->getOptionId($value);
249
+ return $id;
250
+ }
251
+
252
+ private function unSetIndex()
253
+ {
254
+ $processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
255
+ $processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));
256
+ $processes->walk('save');
257
+
258
+ return true;
259
+ }
260
+
261
+ private function setIndex()
262
+ {
263
+ $processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
264
+ $processes->walk('reindexAll');
265
+ $processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));
266
+ $processes->walk('save');
267
+
268
+ return true;
269
+ }
270
+
271
+ }
app/code/community/Shipperhq/Migration/Model/Product/Action.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+
30
+ *
31
+ * @category Mage
32
+ * @package Mage_Catalog
33
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
34
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
+ */
36
+
37
+
38
+ /**
39
+ * Catalog Product Mass processing resource model
40
+ *
41
+ * @category Mage
42
+ * @package Mage_Catalog
43
+ * @author Magento Core Team <core@magentocommerce.com>
44
+ */
45
+ class Shipperhq_Migration_Model_Product_Action extends Mage_Catalog_Model_Resource_Product_Action //extends Mage_Catalog_Model_Resource_Abstract
46
+ {
47
+
48
+ /**
49
+ * Update attribute values for entity list per store
50
+ *
51
+ * @param array $entityIds
52
+ * @param array $attrData
53
+ * @param int $storeId
54
+ * @return Mage_Catalog_Model_Resource_Product_Action
55
+ */
56
+ public function updateAttributes($entityIds, $attrData, $storeId)
57
+ {
58
+ $object = new Varien_Object();
59
+ $object->setIdFieldName('entity_id')
60
+ ->setStoreId($storeId);
61
+
62
+ $this->_getWriteAdapter()->beginTransaction();
63
+ try {
64
+ foreach ($attrData as $attrCode => $value) {
65
+ $attribute = $this->getAttribute($attrCode);
66
+ if (!$attribute->getAttributeId()) {
67
+ continue;
68
+ }
69
+
70
+ $i = 0;
71
+ foreach ($entityIds as $entityId) {
72
+ $i++;
73
+ $object->setId($entityId);
74
+ // collect data for save
75
+ $this->_saveAttributeValue($object, $attribute, $value);
76
+ // save collected data every 1000 rows
77
+ if ($i % 1000 == 0) {
78
+ $this->_processAttributeValues();
79
+ }
80
+ }
81
+ $this->_processAttributeValues();
82
+ }
83
+ $this->_getWriteAdapter()->commit();
84
+ } catch (Exception $e) {
85
+ $this->_getWriteAdapter()->rollBack();
86
+ throw $e;
87
+ }
88
+
89
+ return $this;
90
+ }
91
+
92
+ /**
93
+ * Insert or Update attribute data
94
+ *
95
+ * @param Mage_Catalog_Model_Abstract $object
96
+ * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
97
+ * @param mixed $value
98
+ * @return Mage_Catalog_Model_Resource_Abstract
99
+ */
100
+ protected function _saveAttributeValue($object, $attribute, $value)
101
+ {
102
+ $write = $this->_getWriteAdapter();
103
+ $storeId = (int)Mage::app()->getStore($object->getStoreId())->getId();
104
+ $table = $attribute->getBackend()->getTable();
105
+
106
+ $query = 'SELECT value FROM ' . $table . ' WHERE attribute_id = '
107
+ .$attribute->getAttributeId()
108
+ . ' AND entity_id = ' .$object->getEntityId()
109
+ .' AND store_id = ' .$storeId;
110
+
111
+ $currentValue = $write->fetchOne($query);
112
+ if($currentValue) {
113
+ $valueArray = explode(',', $currentValue);
114
+ if(!in_array($value, $valueArray)) {
115
+ $value = $currentValue .',' .$value;
116
+ }
117
+ }
118
+
119
+ $data = new Varien_Object(array(
120
+ 'entity_type_id' => $attribute->getEntityTypeId(),
121
+ 'attribute_id' => $attribute->getAttributeId(),
122
+ 'store_id' => $storeId,
123
+ 'entity_id' => $object->getEntityId(),
124
+ 'value' => $this->_prepareValueForSave($value, $attribute)
125
+ ));
126
+ $bind = $this->_prepareDataForTable($data, $table);
127
+
128
+ if ($attribute->isScopeStore()) {
129
+ /**
130
+ * Update attribute value for store
131
+ */
132
+ $this->_attributeValuesToSave[$table][] = $bind;
133
+ } else if ($attribute->isScopeWebsite() && $storeId != $this->getDefaultStoreId()) {
134
+ /**
135
+ * Update attribute value for website
136
+ */
137
+ $storeIds = Mage::app()->getStore($storeId)->getWebsite()->getStoreIds(true);
138
+ foreach ($storeIds as $storeId) {
139
+ $bind['store_id'] = (int)$storeId;
140
+ $this->_attributeValuesToSave[$table][] = $bind;
141
+ }
142
+ } else {
143
+ /**
144
+ * Update global attribute value
145
+ */
146
+ $bind['store_id'] = $this->getDefaultStoreId();
147
+ $this->_attributeValuesToSave[$table][] = $bind;
148
+ }
149
+
150
+ return $this;
151
+ }
152
+ }
app/code/community/Shipperhq/Migration/Model/Resource/Iterator/Batched.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ *
30
+ * ST_Core_Model_Resource_Iterator_Batched : https://gist.github.com/kalenjordan/5483065
31
+ * Thanks Kalen
32
+ */
33
+
34
+ class Shipperhq_Migration_Model_Resource_Iterator_Batched extends Varien_Object
35
+ {
36
+ const DEFAULT_BATCH_SIZE = 200;
37
+
38
+ /**
39
+ * @param $collection Varien_Data_Collection
40
+ * @param array $callback
41
+ */
42
+ public function walk($collection, array $callbackForIndividual, array $indCallbackArgs = array(), array $callbackAfterBatch)
43
+ {
44
+ $currentPage = 1;
45
+ $pages = $collection->getLastPageNumber();
46
+ $count = 1;
47
+ do {
48
+ $collection->setCurPage($currentPage);
49
+ $collection->load();
50
+ foreach ($collection as $item) {
51
+ $count++;
52
+ $args = array($item, $indCallbackArgs);
53
+ call_user_func($callbackForIndividual, $args);
54
+ }
55
+ $batchArgs = array('current_page' =>$currentPage, 'total_pages' => $pages);
56
+ call_user_func($callbackAfterBatch, $batchArgs);
57
+
58
+ $currentPage++;
59
+ $collection->clear();
60
+ } while ($currentPage <= $pages);
61
+ return $count;
62
+ }
63
+ }
app/code/community/Shipperhq/Migration/controllers/Adminhtml/Shqmigration/AjaxController.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Migration_Adminhtml_Shqmigration_AjaxController extends Mage_Adminhtml_Controller_Action
32
+ {
33
+ protected static $debug = false;
34
+
35
+ public function migrateSelectAction()
36
+ {
37
+ if ($this->expireAjax()) {
38
+ return;
39
+ }
40
+
41
+ $mtime = microtime();
42
+ $mtime = explode(" ",$mtime);
43
+ $mtime = $mtime[1] + $mtime[0];
44
+ $starttime = $mtime;
45
+
46
+ self::$debug = Mage::helper('shipperhq_shipper')->isDebug();
47
+ $processThese = array();
48
+ if ($this->getRequest()->isGet()) {
49
+ $params = $this->getRequest()->getParams();
50
+ $attributeCode = $this->getRequest()->getParam('attribute_code');
51
+ $toAttributeCode = $this->getRequest()->getParam('to_attribute_code');
52
+ $storeId = (int)$this->getRequest()->getParam('store');
53
+ $attributeToType = $this->getRequest()->getParam('attribute_to_type');
54
+ foreach($params as $key => $value)
55
+ {
56
+ if(strstr($key, $attributeCode)) {
57
+ $processThese[$attributeCode][str_replace($attributeCode.'_','', $key)] = $value;
58
+ }
59
+ }
60
+ }
61
+ $resultSet = array('attribute_code' => $attributeCode);
62
+ $migrator = Mage::getModel('shipperhq_migration/migrate');
63
+ $resultSet['number_updated']= $migrator->migrateAttributeValues($processThese, $attributeCode, $toAttributeCode, $storeId, $attributeToType);
64
+
65
+ $mtime = microtime();
66
+ $mtime = explode(" ",$mtime);
67
+ $mtime = $mtime[1] + $mtime[0];
68
+ $endtime = $mtime;
69
+ $totaltime = ($endtime - $starttime);
70
+
71
+ if(self::$debug) {
72
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq Migration', 'Migrated values of ' .$attributeCode
73
+ .' attribute to ' .$toAttributeCode .' attribute, ' .$resultSet['number_updated'] .' product(s) have been updated'
74
+ ,"This process completed in ".$totaltime." seconds");
75
+ }
76
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($resultSet));
77
+ }
78
+
79
+ public function migrateDefaultAction()
80
+ {
81
+ if ($this->expireAjax()) {
82
+ return;
83
+ }
84
+
85
+ self::$debug = Mage::helper('shipperhq_shipper')->isDebug();
86
+ $numberProcessed = 0;
87
+ $mtime = microtime();
88
+ $mtime = explode(" ",$mtime);
89
+ $mtime = $mtime[1] + $mtime[0];
90
+ $starttime = $mtime;
91
+ if ($this->getRequest()->isGet()) {
92
+ $attributeCode = $this->getRequest()->getParam('attribute_code');
93
+ $storeId = (int)$this->getRequest()->getParam('store');
94
+ $toAttributeCode = $this->getRequest()->getParam('to_attribute_code');
95
+ $resultSet = array('attribute_code' => $attributeCode);
96
+ $migrator = Mage::getSingleton('shipperhq_migration/migrate');
97
+ $result = $migrator->copyAttributeValues($attributeCode, $toAttributeCode, $storeId);
98
+ if($result < 0) {
99
+ $resultSet['error'] = Mage::helper('shipperhq_migration')->__('There was an error saving new attribute values');
100
+ }
101
+ else {
102
+ $numberProcessed+= $result;
103
+ }
104
+ }
105
+ $mtime = microtime();
106
+ $mtime = explode(" ",$mtime);
107
+ $mtime = $mtime[1] + $mtime[0];
108
+ $endtime = $mtime;
109
+ $totaltime = ($endtime - $starttime);
110
+ if(self::$debug) {
111
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq Migration', 'Migrating values of ' .$attributeCode
112
+ .' attribute to ' .$toAttributeCode .' attribute, '
113
+ ,$numberProcessed .' product(s) have been updated ' ."This process completed in ".$totaltime." seconds");
114
+ }
115
+ $resultSet['number_updated']=$numberProcessed;
116
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($resultSet));
117
+ }
118
+
119
+ protected function expireAjax()
120
+ {
121
+ $action = $this->getRequest()->getActionName();
122
+
123
+ if (!in_array($action, array('migrateSelect', 'migrateDefault'))) {
124
+ $this->_ajaxRedirectResponse();
125
+ return true;
126
+ }
127
+
128
+ return false;
129
+ }
130
+
131
+ protected function _ajaxRedirectResponse()
132
+ {
133
+ $this->getResponse()
134
+ ->setHeader('HTTP/1.1', '403 Session Expired')
135
+ ->setHeader('Login-Required', 'true')
136
+ ->sendResponse();
137
+ return $this;
138
+ }
139
+
140
+ }
app/code/community/Shipperhq/Migration/controllers/Adminhtml/ShqmigrationController.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Migration_Adminhtml_ShqmigrationController extends Mage_Adminhtml_Controller_Action
32
+ {
33
+ protected function _initAction()
34
+ {
35
+ $this->loadLayout()
36
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Migration Manager'), Mage::helper('adminhtml')->__('Migration Manager'));
37
+ return $this;
38
+ }
39
+
40
+ public function indexAction()
41
+ {
42
+ $store = $this->getRequest()->getParam('store');
43
+
44
+ $this->loadLayout();
45
+
46
+ //get config of required migratable attributes
47
+ $requiredElements = Mage::helper('shipperhq_migration')->getAttributesToMigrate();
48
+ $switcherBlock = $this->getLayout()
49
+ ->createBlock('adminhtml/store_switcher')
50
+ ->setId('store_switcher')
51
+ ->setName('store_switcher')
52
+ ->setDefaultStoreName($this->__('Default Values'));
53
+ $this->_addContent($switcherBlock);
54
+
55
+ foreach($requiredElements as $attributeToMigrate)
56
+ {
57
+ $moduleId = str_replace(' ','_',$attributeToMigrate['title']);
58
+ $block = $this->getLayout()
59
+ ->createBlock('shipperhq_migration/adminhtml_migration_migratable', $moduleId)
60
+ ->setModuleId($moduleId)
61
+ ->setModuleTitle($attributeToMigrate['title'])
62
+ ->setExtension($attributeToMigrate)
63
+ ->setStore($store);
64
+
65
+ $this->_addContent($block);
66
+ }
67
+
68
+ $this->renderLayout();
69
+ }
70
+
71
+ protected function _isAllowed()
72
+ {
73
+ return Mage::getSingleton('admin/session')->isAllowed('catalog/shipperhq');
74
+ }
75
+
76
+ }
app/code/community/Shipperhq/Migration/etc/adminhtml.xml ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Shipping
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ -->
32
+ <config>
33
+ <menu>
34
+ <catalog>
35
+ <children>
36
+ <shipperhq translate="title" module="shipperhq_shipper">
37
+ <children>
38
+ <migration translate="title" module="shipperhq_migration">
39
+ <title>Migration Manager</title>
40
+ <action>adminhtml/shqmigration</action>
41
+ <sort_order>20</sort_order>
42
+ </migration>
43
+ </children>
44
+ </shipperhq>
45
+ </children>
46
+ </catalog>
47
+ </menu>
48
+ <acl>
49
+ <resources>
50
+ <admin>
51
+ <children>
52
+ <catalog>
53
+ <children>
54
+ <shipperhq>
55
+ <children>
56
+ <migration translate="title" module="shipperhq_migration">
57
+ <title>Migration Manager</title>
58
+ </migration>
59
+ </children>
60
+ </shipperhq>
61
+ </children>
62
+ </catalog>
63
+ </children>
64
+ </admin>
65
+ </resources>
66
+ </acl>
67
+ </config>
app/code/community/Shipperhq/Migration/etc/config.xml ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Shipping
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ -->
32
+ <config>
33
+ <modules>
34
+ <Shipperhq_Migration>
35
+ <version>0.0.1</version>
36
+ </Shipperhq_Migration>
37
+ </modules>
38
+ <admin>
39
+ <routers>
40
+ <adminhtml>
41
+ <args>
42
+ <modules>
43
+ <Shipperhq_Migration after="Mage_Adminhtml">Shipperhq_Migration_Adminhtml</Shipperhq_Migration>
44
+ </modules>
45
+ </args>
46
+ </adminhtml>
47
+ </routers>
48
+ </admin>
49
+ <global>
50
+ <blocks>
51
+ <shipperhq_migration>
52
+ <class>Shipperhq_Migration_Block</class>
53
+ </shipperhq_migration>
54
+ </blocks>
55
+ <helpers>
56
+ <shipperhq_migration>
57
+ <class>Shipperhq_Migration_Helper</class>
58
+ </shipperhq_migration>
59
+ </helpers>
60
+ <models>
61
+ <shipperhq_migration>
62
+ <class>Shipperhq_Migration_Model</class>
63
+ </shipperhq_migration>
64
+ </models>
65
+ </global>
66
+ <adminhtml>
67
+ <layout>
68
+ <updates>
69
+ <shipperhq_migration module="Shipperhq_Migration">
70
+ <file>shipperhq/shipper_migration.xml</file>
71
+ </shipperhq_migration>
72
+ </updates>
73
+ </layout>
74
+ </adminhtml>
75
+ <attribute_migration>
76
+ <dropship>
77
+ <title>WebShopApps Dropship Migration</title>
78
+ <from>Warehouse</from>
79
+ <from_code>warehouse</from_code>
80
+ <to>Origin</to>
81
+ <to_code>shipperhq_warehouse</to_code>
82
+ <no_value_error>You haven't configured any origins in ShipperHQ yet. Log in to your ShipperHQ dashboard and configure then synchronize these with Magento from the Synchronize menu (System > ShipperHQ > Synchronize)</no_value_error>
83
+ </dropship>
84
+ </attribute_migration>
85
+ </config>
app/code/community/Shipperhq/Migration/etc/migrate.xml ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <shipperhq_migrate>
3
+ <modules>
4
+ <dropship>
5
+ <title>WebShopApps Dropship Migration</title>
6
+ <module>Webshopapps_Dropship</module>
7
+ <attributes>
8
+ <!-- this name must be the "from" attribute code-->
9
+ <warehouse>
10
+ <name>warehouse</name>
11
+ <type>select</type>
12
+ <from>
13
+ <code>warehouse</code>
14
+ <title>Warehouse</title>
15
+ <type>select</type>
16
+ </from>
17
+ <to>
18
+ <code>shipperhq_warehouse</code>
19
+ <title>Origin</title>
20
+ <type>multiselect</type>
21
+ </to>
22
+ </warehouse>
23
+ </attributes>
24
+ </dropship>
25
+ <!-- module end -->
26
+ <ship_override>
27
+ <title>WebShopApps Shipping Override Migration</title>
28
+ <module>Webshopapps_Shippingoverride2</module>
29
+ <attributes>
30
+ <shipping_price>
31
+ <name>Shipping Price/Fee</name>
32
+ <type>text</type>
33
+ <from>
34
+ <code>shipping_price</code>
35
+ <title>Shipping Price</title>
36
+ <type>text</type>
37
+ </from>
38
+ <to>
39
+ <code>shipperhq_shipping_fee</code>
40
+ <title>Shipping Fee</title>
41
+ <type>text</type>
42
+ </to>
43
+ </shipping_price>
44
+ <special_shipping_group>
45
+ <name>Special Shipping Group</name>
46
+ <type>select</type>
47
+ <from>
48
+ <code>special_shipping_group</code>
49
+ <title>Special Shipping Group</title>
50
+ <type>select</type>
51
+ </from>
52
+ <to>
53
+ <code>shipperhq_shipping_group</code>
54
+ <title>ShipperHQ Shipping Group</title>
55
+ <type>multiselect</type>
56
+ </to>
57
+ </special_shipping_group>
58
+ </attributes>
59
+ </ship_override>
60
+ <freight_common>
61
+ <title>WebShopApps Freight Shipping</title>
62
+ <module>Webshopapps_Wsafreightcommon</module>
63
+ <attributes>
64
+ <nmfc_class>
65
+ <name>NMFC Class</name>
66
+ <type>text</type>
67
+ <from>
68
+ <code>nmfc_class</code>
69
+ <title>NMFC Class</title>
70
+ <type>text</type>
71
+ </from>
72
+ <to>
73
+ <code>shipperhq_nmfc_class</code>
74
+ <title>ShipperHQ NMFC Class</title>
75
+ <type>text</type>
76
+ </to>
77
+ </nmfc_class>
78
+ <nmfc_sub>
79
+ <name>NMFC Sub Class</name>
80
+ <type>text</type>
81
+ <from>
82
+ <code>nmfc_sub</code>
83
+ <title>NMFC Sub Class</title>
84
+ <type>text</type>
85
+ </from>
86
+ <to>
87
+ <code>shipperhq_shipping_group</code>
88
+ <title>ShipperHQ NMFC Sub Class</title>
89
+ <type>text</type>
90
+ </to>
91
+ </nmfc_sub>
92
+ </attributes>
93
+ </freight_common>
94
+ </modules>
95
+ </shipperhq_migrate>
app/code/community/Shipperhq/Paypalexpress/Model/Express/Checkout.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ *
30
+ * ST_Core_Model_Resource_Iterator_Batched : Kalen Jordan
31
+ */
32
+ class Shipperhq_Paypalexpress_Model_Express_Checkout extends Mage_Paypal_Model_Express_Checkout
33
+ {
34
+
35
+ /*
36
+ * Resolve bug where PayPal displays the code instead of the name
37
+ */
38
+ protected function _prepareShippingOptions(
39
+ Mage_Sales_Model_Quote_Address $address,
40
+ $mayReturnEmpty = false, $calculateTax = false
41
+ ) {
42
+ $options = array(); $i = 0; $iMin = false; $min = false;
43
+ $userSelectedOption = null;
44
+
45
+ foreach ($address->getGroupedAllShippingRates() as $group) {
46
+ foreach ($group as $rate) {
47
+ $amount = (float)$rate->getPrice();
48
+ if ($rate->getErrorMessage()) {
49
+ continue;
50
+ }
51
+ $isDefault = $address->getShippingMethod() === $rate->getCode();
52
+ $amountExclTax = Mage::helper('tax')->getShippingPrice($amount, false, $address);
53
+ $amountInclTax = Mage::helper('tax')->getShippingPrice($amount, true, $address);
54
+
55
+ $options[$i] = new Varien_Object(array(
56
+ 'is_default' => $isDefault,
57
+ 'name' => $rate->getCode(),
58
+ 'code' => trim("{$rate->getCarrierTitle()} - {$rate->getMethodTitle()}", ' -'),
59
+ 'amount' => $amountExclTax,
60
+ ));
61
+ if ($calculateTax) {
62
+ $options[$i]->setTaxAmount(
63
+ $amountInclTax - $amountExclTax
64
+ + $address->getTaxAmount() - $address->getShippingTaxAmount()
65
+ );
66
+ }
67
+ if ($isDefault) {
68
+ $userSelectedOption = $options[$i];
69
+ }
70
+ if (false === $min || $amountInclTax < $min) {
71
+ $min = $amountInclTax;
72
+ $iMin = $i;
73
+ }
74
+ $i++;
75
+ }
76
+ }
77
+
78
+ if ($mayReturnEmpty && is_null($userSelectedOption)) {
79
+ $options[] = new Varien_Object(array(
80
+ 'is_default' => true,
81
+ 'code' => Mage::helper('paypal')->__('N/A'),
82
+ 'name' => 'no_rate',
83
+ 'amount' => 0.00,
84
+ ));
85
+ if ($calculateTax) {
86
+ $options[$i]->setTaxAmount($address->getTaxAmount());
87
+ }
88
+ } elseif (is_null($userSelectedOption) && isset($options[$iMin])) {
89
+ $options[$iMin]->setIsDefault(true);
90
+ }
91
+
92
+ // Magento will transfer only first 10 cheapest shipping options if there are more than 10 available.
93
+ if (count($options) > 10) {
94
+ usort($options, array(get_class($this),'cmpShippingOptions'));
95
+ array_splice($options, 10);
96
+ // User selected option will be always included in options list
97
+ if (!is_null($userSelectedOption) && !in_array($userSelectedOption, $options)) {
98
+ $options[9] = $userSelectedOption;
99
+ }
100
+ }
101
+
102
+ return $options;
103
+ }
104
+
105
+
106
+ /*
107
+ * Reverse code and name in option matching to encompass fix above
108
+ *
109
+ */
110
+ protected function _matchShippingMethodCode(Mage_Sales_Model_Quote_Address $address, $selectedCode)
111
+ {
112
+ $options = $this->_prepareShippingOptions($address, false);
113
+ foreach ($options as $option) {
114
+ if ($selectedCode === $option['code'] // the proper case as outlined in documentation
115
+ || $selectedCode === $option['name'] // workaround: PayPal may return name instead of the code
116
+ // workaround: PayPal may concatenate code and name, and return it instead of the code:
117
+ || $selectedCode === "{$option['code']} {$option['name']}"
118
+ ) {
119
+ return $option['name'];
120
+ }
121
+ }
122
+ return '';
123
+ }
124
+
125
+
126
+ }
app/code/community/Shipperhq/Paypalexpress/etc/config.xml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Shipping
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ -->
32
+ <config>
33
+ <modules>
34
+ <Shipperhq_Paypalexpress>
35
+ <version>0.0.1</version>
36
+ </Shipperhq_Paypalexpress>
37
+ </modules>
38
+ <global>
39
+ <models>
40
+ <paypal>
41
+ <rewrite>
42
+ <express_checkout>Shipperhq_Paypalexpress_Model_Express_Checkout</express_checkout>
43
+ </rewrite>
44
+ </paypal>
45
+ </models>
46
+ </global>
47
+ </config>
app/code/community/Shipperhq/Pbint/Block/Adminhtml/System/Upload.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Block_Adminhtml_System_Upload extends Mage_Adminhtml_Block_System_Config_Form_Field
32
+ {
33
+
34
+ protected function _prepareLayout()
35
+ {
36
+ parent::_prepareLayout();
37
+ if (!$this->getTemplate()) {
38
+ $this->setTemplate('shipperhq/upload.phtml');
39
+ }
40
+ return $this;
41
+ }
42
+
43
+ /**
44
+ * Unset some non-related element parameters
45
+ *
46
+ * @param Varien_Data_Form_Element_Abstract $element
47
+ * @return string
48
+ */
49
+ public function render(Varien_Data_Form_Element_Abstract $element)
50
+ {
51
+ $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
52
+ return parent::render($element);
53
+ }
54
+
55
+ /**
56
+ * Get the button and scripts contents
57
+ *
58
+ * @param Varien_Data_Form_Element_Abstract $element
59
+ * @return string
60
+ */
61
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
62
+ {
63
+ $originalData = $element->getOriginalData();
64
+ $this->addData(array(
65
+ 'button_label' => Mage::helper('customer')->__($originalData['button_label']),
66
+ 'html_id' => $element->getHtmlId(),
67
+ 'ajax_url' => Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/Shqpitney/uploadcatalog')
68
+ ));
69
+
70
+ return $this->_toHtml();
71
+ }
72
+
73
+ }
app/code/community/Shipperhq/Pbint/Block/Sales/Order/Duty.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Block_Sales_Order_Duty extends Mage_Core_Block_Abstract
32
+ {
33
+ public function getSource()
34
+ {
35
+ return $this->getParentBlock()->getSource();
36
+ }
37
+
38
+ /**
39
+ * Add this total to parent
40
+ */
41
+ public function initTotals()
42
+ {
43
+ if ((float)$this->getSource()->getShqPbDutyAmount() == 0) {
44
+ return $this;
45
+ }
46
+ $total = new Varien_Object(array(
47
+ 'code' => 'shq_pb_duty',
48
+ 'field' => 'shq_pb_duty_amount',
49
+ 'value' => $this->getSource()->getShqPbDutyAmount(),
50
+ 'label' => $this->__('International Duty')
51
+ ));
52
+ $this->getParentBlock()->addTotalBefore($total, 'shipping');
53
+ return $this;
54
+ }
55
+ }
app/code/community/Shipperhq/Pbint/Helper/Data.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Pitney Bowes International
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Pbint_Helper_Data extends Mage_Core_Helper_Abstract
32
+ {
33
+ protected static $_debug;
34
+ protected static $code = 'pitney';
35
+ /**
36
+ * Retrieve debug configuration
37
+ * @return boolean
38
+ */
39
+ public function isDebug()
40
+ {
41
+ if (self::$_debug == NULL) {
42
+ self::$_debug = Mage::helper('wsalogger')->isDebug('Shipperhq_Pbint');
43
+ }
44
+ return self::$_debug;
45
+ }
46
+
47
+ public function isPbOrder($carrierType)
48
+ {
49
+ if($carrierType == self::$code) {
50
+ if ($this->isDebug()) {
51
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
52
+ 'Carrier type is Pitney Bowes International via ShipperHQ', $carrierType);
53
+ }
54
+ return true;
55
+ }
56
+ if ($this->isDebug()) {
57
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
58
+ 'Carrier type is not Pitney Bowes International via ShipperHQ', $carrierType);
59
+
60
+ }
61
+ return false;
62
+
63
+ }
64
+ }
app/code/community/Shipperhq/Pbint/Model/Catalog/Category.php ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Catalog_Category
32
+ {
33
+ protected $category;
34
+ private static $roots;
35
+ protected $url;
36
+ protected $_debug;
37
+
38
+ public function __construct($id, $url = null)
39
+ {
40
+
41
+ $this->_debug = Mage::helper('shipperhq_pbint')->isDebug();
42
+ if (gettype($id) == "object" && $id instanceOf Mage_Catalog_Model_Category) {
43
+ $this->category = $id;
44
+ } else {
45
+ $this->category = Mage::getModel('catalog/category')->load($id);
46
+ }
47
+ $this->url = $url;
48
+ }
49
+
50
+ public function getCategory()
51
+ {
52
+ return $this->category;
53
+ }
54
+
55
+ public function getName()
56
+ {
57
+ return $this->category->getName();
58
+ }
59
+
60
+ public function getCode()
61
+ {
62
+ return $this->category->getId();
63
+ }
64
+
65
+ public function getUrl()
66
+ {
67
+ if ($this->_debug) {
68
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
69
+ 'Category processing, url is ', $this->category->getUrl() );
70
+ }
71
+ if ($this->url)
72
+ return $this->url;
73
+ return $this->category->getUrl();
74
+ }
75
+
76
+ public function isRoot()
77
+ {
78
+ if (!$this->category->getParentId()) {
79
+ return true;
80
+ }
81
+ if (!self::$roots) {
82
+ $categoryOp = new Mage_Adminhtml_Block_Catalog_Category_Abstract();
83
+ self::$roots = $categoryOp->getRootIds();
84
+ }
85
+ foreach (self::$roots as $rootId) {
86
+ if ($this->getCode() == $rootId) {
87
+ return true;
88
+ }
89
+ }
90
+ return false;
91
+ }
92
+
93
+ public function getParentCode()
94
+ {
95
+ return $this->category->getParentId();
96
+ }
97
+
98
+ public function writeToFile($file)
99
+ {
100
+ $name = Shipperhq_Pbint_Model_Catalog_File::stripHtml($this->getName());
101
+ $name = preg_replace("/[,.\-\+=;:\\(){}\[\]@?%$#]/", '', $name);
102
+ $parentCateID = '';
103
+ if ($this->getParentCode() != 1 && !$this->isRoot()) {
104
+ $parentCateID = $this->getParentCode();
105
+ }
106
+ fputcsv($file, array($this->getCode(), $parentCateID, $name, '', $this->getUrl()));
107
+ }
108
+
109
+ public function upload()
110
+ {
111
+ if ($this->_debug) {
112
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
113
+ 'Uploading category: ', $this->category->getName() . "... " );
114
+ }
115
+
116
+ if (Shipperhq_Pbint_Model_Api::addCategory($this)) {
117
+ if ($this->_debug) {
118
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
119
+ 'Uploading category result: ', 'OK');
120
+ }
121
+ } else {
122
+ if ($this->_debug) {
123
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
124
+ 'Uploading category result: ', 'Failed');
125
+ }
126
+ }
127
+ $products = $this->category->getProductCollection();
128
+
129
+ foreach ($products as $product) {
130
+ $clearPathProduct = new Shipperhq_Pbint_Model_Catalog_Product($product);
131
+ if ($this->_debug) {
132
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
133
+ 'Uploading product: ',$clearPathProduct->getName() . "... ");
134
+ }
135
+ if (Shipperhq_Pbint_Model_Api::addCommodity($clearPathProduct)) {
136
+ if ($this->_debug) {
137
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
138
+ 'Uploading product: ',$clearPathProduct->getName() . " - OK");
139
+ }
140
+ } else {
141
+ if ($this->_debug) {
142
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
143
+ 'Uploading product: ',$clearPathProduct->getName() . " - Failed");
144
+ }
145
+ }
146
+ }
147
+
148
+
149
+ $children = $this->category->getChildrenCategories();
150
+
151
+ // TODO: this code will run out of memory if there are a lot of categories....
152
+ // Need to convert the recursive call to a loop at some point.
153
+ foreach ($children as $child) {
154
+ $childCategory = new Shipperhq_Pbint_Model_Catalog_Category($child);
155
+ $childCategory->upload();
156
+ }
157
+ }
158
+
159
+ // TODO This fuction starts at the Magento root and its not very efficient... see isRoot for proper implementation.
160
+ // This function is only used by the API upload.
161
+ public static function getAllRootCategories()
162
+ {
163
+ $roots = array();
164
+
165
+ $categories = Mage::getModel('catalog/category')->getCollection(); //->getSelect()->order(array('IF(`id`>0, `id`, 9999) ASC'));
166
+ $categories = $categories->getIterator();
167
+
168
+ foreach ($categories as $category) {
169
+ $parents = $category->getParentId();
170
+ if (!$parents) {
171
+ $rootCategory = new Shipperhq_Pbint_Model_Catalog_Category($category->getId());
172
+ array_push($roots, $rootCategory);
173
+ }
174
+ }
175
+ return $roots;
176
+ }
177
+
178
+ }
179
+
180
+ ?>
app/code/community/Shipperhq/Pbint/Model/Catalog/Cron.php ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Catalog_Cron
32
+ {
33
+
34
+ private $lastDiff;
35
+ private $lastFull;
36
+
37
+ protected $_debug;
38
+
39
+ public function catalogSync()
40
+ {
41
+ $this->_debug = Mage::helper('shipperhq_pbint')->isDebug();
42
+ if ($this->_debug) {
43
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
44
+ 'Catalog synch', 'Synchronization starting');
45
+ }
46
+ $diffPeriod = Mage::getStoreConfig('shipperhqpitney/shqpbint/catalog_diff');
47
+ $fullPeriod = Mage::getStoreConfig('shipperhqpitney/shqpbint/catalog_full');
48
+
49
+ $collection = Mage::getModel("shipperhq_pbint/variable")->getCollection();
50
+ foreach ($collection as $variable) {
51
+ if ($this->_debug) {
52
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
53
+ 'Processing: ', $variable->getName() . " -> " . $variable->getValue());
54
+ }
55
+ if ($variable->getName() == "lastFull") {
56
+ $this->lastFull = $variable;
57
+ }
58
+ if ($variable->getName() == "lastDiff") {
59
+ $this->lastDiff = $variable;
60
+ }
61
+ }
62
+
63
+
64
+ $appRoot = Mage::getRoot();
65
+ $mageRoot = dirname($appRoot);
66
+ $configOptions = Mage::getModel('core/config_options');
67
+ $configOptions->createDirIfNotExists($mageRoot . '/var/pbint');
68
+ chmod($mageRoot . '/var/pbint/', 0777);
69
+
70
+ if (!isset($this->lastFull) || $this->lastFull->getValue() < time() - $fullPeriod * 24 * 3600) {
71
+ // Full catalog upload needed
72
+ $this->uploadCatalog();
73
+ } else if (!isset($this->lastDiff) && $this->lastFull->getValue() < time() - $diffPeriod * 3600) {
74
+ // First catalog diff upload
75
+ $this->uploadCatalog($this->lastFull);
76
+ } else if (isset($this->lastDiff) && ($this->lastDiff->getValue() < time() - $diffPeriod * 3600 &&
77
+ $this->lastFull->getValue() < time() - $diffPeriod * 3600)
78
+ ) {
79
+ // Catalog diff upload
80
+ $this->uploadCatalog($this->lastDiff);
81
+ } else {
82
+ if ($this->_debug) {
83
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
84
+ 'PB Export cron.', 'Do not export catalog');
85
+ }
86
+ }
87
+
88
+ }
89
+
90
+ public function uploadCatalog($lastDiff = false)
91
+ {
92
+ $this->_debug = Mage::helper('shipperhq_pbint')->isDebug();
93
+ if (!$lastDiff) {
94
+ if ($this->_debug) {
95
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
96
+ 'PB Synch', 'Full catalog upload');
97
+ }
98
+ $file = new Shipperhq_Pbint_Model_Catalog_File();
99
+ if (isset($this->lastFull)) {
100
+ $this->lastFull->setValue(time());
101
+ } else {
102
+ $this->lastFull = Mage::getModel("shipperhq_pbint/variable");
103
+ $this->lastFull->setName("lastFull");
104
+ $this->lastFull->setValue(time());
105
+ }
106
+ $this->lastFull->save();
107
+ } else {
108
+ if ($this->_debug) {
109
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
110
+ 'PB Synch', 'Catalog diff');
111
+ }
112
+ $file = new Shipperhq_Pbint_Model_Catalog_File($lastDiff->getValue());
113
+ if (isset($this->lastDiff)) {
114
+ $this->lastDiff->setValue(time());
115
+ } else {
116
+ $this->lastDiff = Mage::getModel("shipperhq_pbint/variable");
117
+ $this->lastDiff->setName("lastDiff");
118
+ $this->lastDiff->setValue(time());
119
+ }
120
+ $this->lastDiff->save();
121
+ }
122
+
123
+ if ($this->_debug) {
124
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
125
+ 'Catalog synch', 'Create function started');
126
+ }
127
+ $result = $file->createNew();
128
+ if ($this->_debug) {
129
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
130
+ 'Catalog synch', 'Create function complete');
131
+ }
132
+
133
+ $result = $file->upload();
134
+ $file->logProdWithoutCategories();
135
+ if ($this->_debug) {
136
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
137
+ 'PB Synch', 'Upload Complete');
138
+ }
139
+ return $result;
140
+ }
141
+
142
+ public function processStatusNotifications()
143
+ {
144
+ $file = new Shipperhq_Pbint_Model_Catalog_File();
145
+ $file->processStatusNotifications();
146
+ }
147
+
148
+ }
149
+
150
+
151
+ ?>
app/code/community/Shipperhq/Pbint/Model/Catalog/File.php ADDED
@@ -0,0 +1,862 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Pitney Bowes International
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+ /* Creates a temporary file containing a Pb catalog xml file. Because of possible PHP timeouts the creation of the
31
+ * xml file is done in concrete steps that can be resumed in case of a timeout.
32
+ */
33
+
34
+ class Shipperhq_Pbint_Model_Catalog_File
35
+ {
36
+
37
+
38
+ private $file;
39
+ private $filename;
40
+ private $lastDiff;
41
+ private $productIds;
42
+ private $lastFileName;
43
+
44
+ protected $_debug;
45
+
46
+ public function __construct($lastDiff = false)
47
+ {
48
+ $this->lastDiff = $lastDiff;
49
+ $this->productIds = array();
50
+ }
51
+
52
+ private function _getTempDir()
53
+ {
54
+ $appRoot = Mage::getRoot();
55
+ $mageRoot = dirname($appRoot);
56
+ $configOptions = Mage::getModel('core/config_options');
57
+ $tmpDir = $mageRoot . '/var/pbint/tmp/';
58
+ $configOptions->createDirIfNotExists($tmpDir);
59
+ chmod($tmpDir, 0777);
60
+ return $tmpDir;
61
+ }
62
+
63
+
64
+ private function _getDataFileName($dataFeedName, $part = null)
65
+ {
66
+ $partName = '';
67
+ if ($part)
68
+ $partName = '_part' . $part;
69
+ $fileName = Shipperhq_Pbint_Model_Credentials::getCatalogSenderID() . "_" . $dataFeedName . "_update_" . Shipperhq_Pbint_Model_Credentials::getPBID() . '_' . date('Ymd_His') . '_' . mt_rand(100000, 999999);
70
+ if ($part == 1)
71
+ $this->lastFileName = $fileName;
72
+ else
73
+ $fileName = $this->lastFileName;
74
+ return $fileName . $partName . '.csv';
75
+ }
76
+
77
+ private function _createNewCommoditiyFile($part = null)
78
+ {
79
+ $fileName = $this->_getDataFileName('catalog', $part);
80
+ if(is_resource($this->file)) {
81
+ fflush($this->file);
82
+
83
+ fclose($this->file);
84
+
85
+ }
86
+
87
+ $this->filename = $this->_getTempDir() . $fileName;
88
+ if ($this->_debug) {
89
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
90
+ 'Product catalog upload - creating new commodity file', $fileName);
91
+ }
92
+ try {
93
+ $this->file = fopen($this->filename, "w+");
94
+ chmod($this->filename, 0777);
95
+ }
96
+ catch(Exception $e) {
97
+ if ($this->_debug) {
98
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint',
99
+ 'Product catalog upload exception during file opening', $e->getMessage());
100
+ }
101
+ }
102
+
103
+ //add header row
104
+ fputcsv($this->file, array('MERCHANT_COMMODITY_REF_ID', 'COMMODITY_NAME_TITLE', 'SHORT_DESCRIPTION',
105
+ 'LONG_DESCRIPTION', 'RETAILER_ID', 'COMMODITY_URL', 'RETAILER_UNIQUE_ID', 'PCH_CATEGORY_ID',
106
+ 'RH_CATEGORY_ID', 'STANDARD_PRICE', 'WEIGHT_UNIT', 'DISTANCE_UNIT', 'COO', 'IMAGE_URL', 'PARENT_SKU',
107
+ 'CHILD_SKU', 'PARCELS_PER_SKU', 'UPC', 'UPC_CHECK_DIGIT', 'GTIN', 'MPN', 'ISBN', 'BRAND', 'MANUFACTURER',
108
+ 'MODEL_NUMBER', 'MANUFACTURER_STOCK_NUMBER', 'COMMODITY_CONDITION', 'COMMODITY_HEIGHT',
109
+ 'COMMODITY_WIDTH', 'COMMODITY_LENGTH', 'PACKAGE_WEIGHT', 'PACKAGE_HEIGHT', 'PACKAGE_WIDTH',
110
+ 'PACKAGE_LENGTH', 'HAZMAT', 'ORMD', 'CHEMICAL_INDICATOR', 'PESTICIDE_INDICATOR', 'AEROSOL_INDICATOR',
111
+ 'RPPC_INDICATOR', 'BATTERY_TYPE', 'NON_SPILLABLE_BATTERY', 'FUEL_RESTRICTION', 'SHIP_ALONE',
112
+ 'RH_CATEGORY_ID_PATH', 'RH_CATEGORY_NAME_PATH'));
113
+ //,'RH_CATEGORY_URL_PATH','GPC','COMMODITY_WEIGHT','HS_CODE','CURRENCY'
114
+
115
+ fflush($this->file);
116
+ }
117
+
118
+ private function _createNewCategoryFile($part = null)
119
+ {
120
+ if(is_resource($this->file)) {
121
+ fflush($this->file);
122
+ fclose($this->file);
123
+
124
+ }
125
+
126
+ $fileName = $this->_getDataFileName('category-tree', $part);
127
+
128
+
129
+ $this->filename = $this->_getTempDir() . $fileName;
130
+ if ($this->_debug) {
131
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
132
+ 'Product catalog upload - creating new category file', $fileName);
133
+ }
134
+ try {
135
+ $this->file = fopen($this->filename, "w+");
136
+ chmod($this->filename, 0777);
137
+ }
138
+ catch(Exception $e) {
139
+ if ($this->_debug) {
140
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint',
141
+ 'Product catalog upload exception during file opening', $e->getMessage());
142
+ }
143
+ }
144
+ //add header row
145
+ fputcsv($this->file, array('CATEGORY_ID', 'PARENT_CATEGORY_ID', 'NAME',
146
+ 'ID_PATH', 'URL'));
147
+
148
+ fflush($this->file);
149
+ }
150
+
151
+
152
+ private function _getSelectedCategory($categories, $catId)
153
+ {
154
+ foreach ($categories as $cat) {
155
+ if ($cat->getId() == $catId)
156
+ return $cat;
157
+ }
158
+ return false;
159
+ }
160
+
161
+ /**
162
+ * Extracts the categories and products and exports them into xml file.
163
+ */
164
+ public function createNew()
165
+ {
166
+ $this->_debug = Mage::helper('shipperhq_pbint')->isDebug();
167
+
168
+ $maxRecordsCount = Shipperhq_Pbint_Model_Credentials::getMaxRecordsCount();
169
+ if (!$maxRecordsCount) {
170
+ $maxRecordsCount = 10000;
171
+ }
172
+
173
+ if ($this->_debug) {
174
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
175
+ 'ShipperHQ Pitney product catalog upload', 'Maxium number of records: ' .$maxRecordsCount);
176
+ }
177
+ $prodCount = 0;
178
+ $catCount = 0;
179
+ $fileRecordCount = 0;
180
+ //get stores which has disabled clearpath
181
+ $stores = Mage::app()->getStores();
182
+ $defaultStoreUrl = Mage::getBaseUrl();
183
+ $secDefaultStoreUrl = str_replace("http", "https", $defaultStoreUrl);
184
+ $disabledStores = array();
185
+ $addedCategories = array();
186
+ $part = 1;
187
+ $atLeastOneStoreEnabled = false;
188
+ if ($this->_debug) {
189
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
190
+ 'ShipperHQ Pitney product catalog upload', 'Number of stores in Magento: ' .count($stores));
191
+ }
192
+ foreach ($stores as $store) {
193
+
194
+ $isActive = Mage::getStoreConfig('shipperhqpitney/shqpbint/active', $store);
195
+ $baseURL = $store->getBaseUrl();
196
+
197
+ if (!$isActive) {
198
+ $disabledStores[] = $store;
199
+ if ($this->_debug) {
200
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
201
+ 'Disabled store ', $store->getId() . ' ' . $store->getCode());
202
+ }
203
+ } else {
204
+ $atLeastOneStoreEnabled = true;
205
+ $rootId = Mage::app()->getStore($store->getId())->getRootCategoryId();
206
+ $rootCat = Mage::getModel('catalog/category')->load($rootId);
207
+ /* @var $rootCat Mage_Catalog_Model_Category */
208
+ $rootCat->setData('store', $store);
209
+ if ($this->_debug) {
210
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
211
+ 'Default store url ', $defaultStoreUrl . 'store ' . $store->getCode() . ' store base url'
212
+ . $baseURL . " root cat url" . $rootCat->getUrl() . " cat name" . $rootCat->getName());
213
+ }
214
+
215
+ $catUrl = str_replace($defaultStoreUrl, $baseURL, $rootCat->getUrl());
216
+ if ($catUrl == $rootCat->getUrl())
217
+ $catUrl = str_replace($secDefaultStoreUrl, $baseURL, $rootCat->getUrl());
218
+ $cat = new Shipperhq_Pbint_Model_Catalog_Category($rootCat, $catUrl);
219
+ if (!$this->file || $fileRecordCount > $maxRecordsCount) {
220
+ $this->_createNewCategoryFile($part);
221
+ $fileRecordCount = 0;
222
+ $part++;
223
+ }
224
+ $cat->writeToFile($this->file);
225
+ fflush($this->file);
226
+ $catCount++;
227
+ $fileRecordCount++;
228
+ $categories = Mage::getModel('catalog/category')
229
+ ->getCollection()
230
+ ->addUrlRewriteToResult()
231
+ ->addAttributeToSelect('name')
232
+ ->addFieldToFilter('path', array('like' => "1/$rootId/%"));
233
+ $addedCategories[] = $rootCat;
234
+ if ($this->_debug) {
235
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
236
+ 'Product catalog upload ', 'Found ' .count($categories) .' for processing');
237
+ }
238
+ foreach ($categories as $category) {
239
+ if (!$this->file || $fileRecordCount > $maxRecordsCount) {
240
+ $this->_createNewCategoryFile($part);
241
+ $fileRecordCount = 0;
242
+ $part++;
243
+ }
244
+ /* @var $category Mage_Catalog_Model_Category */
245
+ $category->setStoreId($store->getId());
246
+ $category->setData('store', $store);
247
+ $addedCategories[] = $category;
248
+
249
+ $catUrl = str_replace($defaultStoreUrl, $baseURL, $category->getUrl());
250
+ if ($catUrl == $category->getUrl())
251
+ $catUrl = str_replace($secDefaultStoreUrl, $baseURL, $category->getUrl());
252
+ $cat = new Shipperhq_Pbint_Model_Catalog_Category($category, $catUrl);
253
+ $cat->writeToFile($this->file);
254
+ fflush($this->file);
255
+ $catCount++;
256
+ $fileRecordCount++;
257
+ }
258
+ }
259
+ }
260
+ if(!$atLeastOneStoreEnabled) {
261
+ if ($this->_debug) {
262
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Pbint',
263
+ 'Product catalog upload issue ', ' ShipperHQ Pitney is not set to active for any of your stores,
264
+ Please enable in at least one store before attempting to upload catalog');
265
+ }
266
+ }
267
+ if($this->file) {
268
+ fclose($this->file);
269
+ }
270
+ else {
271
+ if ($this->_debug) {
272
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Pbint',
273
+ 'Product catalog upload issue ', 'No upload file object was created');
274
+ }
275
+ }
276
+ $this->_stripPartFromFileName($part);
277
+ //fwrite($this->file,"</CategoryList>\n<CommodityList>\n");
278
+ $fileRecordCount = 0;
279
+ $part = 1;
280
+ $this->_createNewCommoditiyFile($part);
281
+ $part++;
282
+ $addedProducts = array();
283
+ if(count($addedCategories) == 0) {
284
+ if ($this->_debug) {
285
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Pbint',
286
+ 'Product catalog upload ', 'During processing, no product categories were found. Please review full log files for details');
287
+ }
288
+ }
289
+
290
+ $productCollection = Mage::getModel('catalog/product')->getCollection()
291
+ ->addAttributeToSelect('name')
292
+ ->addAttributeToSelect('sku')
293
+ ->addAttributeToSelect('country_of_manufacture')
294
+ ->addAttributeToSelect('description')
295
+ ->addAttributeToSelect('product_url')
296
+ ->addAttributeToSelect('type_id')
297
+ ->addAttributeToSelect('shipperhq_pbint_upload')
298
+ ->addAttributeToSelect('price')
299
+ ->addAttributeToSelect('weight');
300
+
301
+ $productCollection->setPageSize(100);
302
+
303
+ $pages = $productCollection->getLastPageNumber();
304
+ if ($this->_debug) {
305
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
306
+ 'Product catalog upload ', 'There are ' .$pages.' pages x 100 products to process');
307
+ }
308
+ $currentPage = 1;
309
+
310
+ do {
311
+ $productCollection->setCurPage($currentPage);
312
+ $productCollection->load();
313
+
314
+ foreach ($productCollection as $product) {
315
+ if ($product->getTypeId() == 'virtual') {
316
+ continue;
317
+ }
318
+
319
+ if ($product->getTypeId() == 'configurable' || $product->getTypeId() == 'bundle') {
320
+ //as we'll use the child products only
321
+ continue;
322
+ }
323
+
324
+ $cateIds = $product->getCategoryIds();
325
+ $cateId = 0;
326
+ foreach ($cateIds as $cId) {
327
+ $cateId = $cId; //get lower level of category
328
+ }
329
+
330
+ $prodCat = $this->_getSelectedCategory($addedCategories, $cateId);
331
+ if (!$prodCat) {
332
+ $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')
333
+ ->getParentIdsByChild($product->getId());
334
+ if(empty($parentIds)) {
335
+ $parentIds = Mage::getResourceSingleton('bundle/selection')
336
+ ->getParentIdsByChild($product->getId());
337
+ if(empty($parentIds)) {
338
+ if ($this->_debug) {
339
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
340
+ 'Product catalog upload ', 'unable to find an exported category for SKU ' .$product->getSku() .' and no assigned parents on this product');
341
+ }
342
+ continue;
343
+ }
344
+ }
345
+ $parent = Mage::getModel('catalog/product')->load($parentIds[0]);
346
+ foreach ($parent->getCategoryIds() as $cId) {
347
+ $cateId = $cId; //get lower level of category
348
+ }
349
+ $prodCat = $this->_getSelectedCategory($addedCategories, $cateId);
350
+ if(!$prodCat) {
351
+ if ($this->_debug) {
352
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
353
+ 'Product catalog upload ', 'unable to find an exported category for SKU ' .$product->getSku() .' - category ID is ' .$cateId);
354
+ }
355
+ continue; //can't find the category
356
+ }
357
+ }
358
+ $baseURL = Mage::app()->getStore($category->getStoreId())->getBaseUrl();
359
+ $productUrlFormat = $baseURL . "catalog/product/view/id/%d/";
360
+
361
+ $cIds = explode('/', $prodCat->getPath());
362
+ $cIds = array_slice($cIds, 1); //remove root category
363
+ $prodCat->setData('id_path', implode(':', $cIds));
364
+ $prodCat->setData('name_path', $this->_getCatNamePath($addedCategories, $cIds));
365
+
366
+ $pbProduct = new Shipperhq_Pbint_Model_Catalog_Product($product, sprintf($productUrlFormat, $product->getId()));
367
+ if ($fileRecordCount > $maxRecordsCount) {
368
+ $this->_createNewCommoditiyFile();
369
+ $fileRecordCount = 0;
370
+ $part++;
371
+ }
372
+ $this->writeProduct($pbProduct, $cateId, null, $prodCat);
373
+ $prodCount++;
374
+ $fileRecordCount++;
375
+ $addedProducts[$product->getSku()] = "added";
376
+
377
+ }
378
+
379
+ $currentPage++;
380
+ //clear collection and free memory
381
+ $productCollection->clear();
382
+ } while ($currentPage <= $pages);
383
+
384
+ if($this->file) {
385
+ fflush($this->file);
386
+ }
387
+ if ($this->_debug) {
388
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
389
+ 'Product upload - Completed file creation', 'Processed ' .$prodCount .' products');
390
+ }
391
+
392
+ $this->_stripPartFromFileName($part);
393
+ return true;
394
+ }
395
+
396
+ private function _getCatNamePath($categories, $cateIds)
397
+ {
398
+
399
+ $names = array();
400
+ foreach ($cateIds as $id) {
401
+ foreach ($categories as $cat) {
402
+ if ($cat->getId() == $id) {
403
+ array_push($names, $cat->getName());
404
+ break;
405
+ }
406
+ }
407
+ }
408
+ return implode('|', $names);
409
+ }
410
+
411
+ /**
412
+ * Updates the shipperhq_pbint_upload time in all uploaded products
413
+ */
414
+ public function updateLastProductUpload()
415
+ {
416
+
417
+ $this->_debug = Mage::helper('shipperhq_pbint')->isDebug();
418
+ $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'shipperhq_pbint_upload');
419
+ if (!$attribute->getAttributeId()) {
420
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
421
+ $setup->addAttribute('catalog_product', 'shipperhq_pbint_upload', array(
422
+ 'label' => 'Last Pb upload timestampt',
423
+ 'type' => 'varchar',
424
+ 'input' => 'text',
425
+ 'visible' => false,
426
+ 'required' => false,
427
+ 'position' => 1,
428
+ ));
429
+ }
430
+
431
+ $productIds = array_unique($this->productIds);
432
+ if ($this->_debug) {
433
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
434
+ 'Uploaded products', count($productIds));
435
+ }
436
+ $updated = 0;
437
+ foreach ($productIds as $prodId) {
438
+ $product = Mage::getModel("catalog/product")->load($prodId);
439
+ $product->setPbPbgspUpload(time());
440
+ try {
441
+ $product->save();
442
+ $updated++;
443
+ } catch (Exception $e) {
444
+ if ($this->_debug) {
445
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint',
446
+ 'There was a problem saving the product with sku', $product->getSku() . " Error Message \n" . $e->getMessage());
447
+ }
448
+ }
449
+
450
+ }
451
+ if ($this->_debug) {
452
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
453
+ 'shipperhq_pbint_upload', $updated . ' products updated');
454
+ }
455
+ }
456
+
457
+ /**
458
+ * Uploads the xml file to clearpath SFTP server
459
+ */
460
+
461
+ private function _getNotificationDir()
462
+ {
463
+ $tmpDir = $this->_getTempDir();
464
+ $configOptions = Mage::getModel('core/config_options');
465
+ $notificationDir = $tmpDir . 'notifications';
466
+ $configOptions->createDirIfNotExists($notificationDir);
467
+ chmod($notificationDir, 0777);
468
+ return $notificationDir;
469
+ }
470
+
471
+ public function processStatusNotifications()
472
+ {
473
+ $this->_debug = Mage::helper('shipperhq_pbint')->isDebug();
474
+ try {
475
+ $adminEmail = Shipperhq_Pbint_Model_Credentials::getAdminEmail();
476
+ if (!isset($adminEmail) || $adminEmail == '')
477
+ return;
478
+ $notificationDir = $this->_getNotificationDir();
479
+ $this->_downloadStatusNotifications($notificationDir);
480
+ $notificationFiles = array_diff(scandir($notificationDir), array('..', '.'));
481
+ if (count($notificationFiles) > 0) {
482
+ $mail = new Zend_Mail();
483
+ $mail->setFrom('no-reply@pb.com', 'Pitney Bowes');
484
+ $mail->addTo($adminEmail)
485
+ ->setSubject('Catalog Export Error')
486
+ ->setBodyText('Catalog Export Error. Please see attached files.');
487
+ $fileCount = 0;
488
+ foreach ($notificationFiles as $notificationFile) {
489
+ if ($this->_endsWith($notificationFile, '.err') || $this->_endsWith($notificationFile, '.log')) {
490
+ $file = $notificationDir . '/' . $notificationFile;
491
+ $at = new Zend_Mime_Part(file_get_contents($file));
492
+ $at->filename = basename($file);
493
+ $at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
494
+ $at->encoding = Zend_Mime::ENCODING_8BIT;
495
+
496
+ $mail->addAttachment($at);
497
+ $fileCount++;
498
+ }
499
+
500
+ }
501
+ if ($fileCount > 0) {
502
+ $mail->send();
503
+ if ($this->_debug) {
504
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
505
+ 'ProcessStatusNotifications', 'Email sent with error files.');
506
+ }
507
+ } else {
508
+ if ($this->_debug) {
509
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
510
+ 'ProcessStatusNotifications', 'No error files found.');
511
+ }
512
+ }
513
+ //keep these files until next upload and delete files from old upload
514
+ $this->_cleanNotificationFiles();
515
+ }
516
+ } catch (Exception $e) {
517
+ if ($this->_debug) {
518
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint',
519
+ 'ProcessStatusNotifications', 'Error in processStatusNotifications:' . $e->getMessage());
520
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint',
521
+ 'Full trace of exception: ', $e->getTraceAsString());
522
+ }
523
+ }
524
+ }
525
+
526
+ private function _cleanNotificationFiles()
527
+ {
528
+ //keep resent files until next upload and delete files from old upload
529
+ $lastExportedFiles = $this->_getLastExportedFileNames();
530
+ if (!$lastExportedFiles)
531
+ return;
532
+ $notificationDir = $this->_getNotificationDir();
533
+ $notificationFiles = array_diff(scandir($notificationDir), array('..', '.'));
534
+
535
+ foreach ($notificationFiles as $notificationFile) {
536
+ $path_parts = pathinfo($notificationFile);
537
+ $localFileNameWithoutExt = $path_parts['filename'];
538
+ $isOldFile = true;
539
+ foreach ($lastExportedFiles as $lastExportedFile) {
540
+ $lastExportedFileNameWithoutExt = str_replace('.gpg', '', str_replace('.csv', '', $lastExportedFile));
541
+ if ($lastExportedFileNameWithoutExt == $localFileNameWithoutExt) {
542
+ $isOldFile = false;
543
+ break;
544
+ }
545
+ }
546
+ if ($isOldFile) {
547
+ //this is from 2nd last upload, remove it from disk
548
+ unlink($notificationDir . '/' . $notificationFile);
549
+ }
550
+ }
551
+
552
+ }
553
+
554
+ private function _downloadStatusNotifications($notificationDir)
555
+ {
556
+
557
+ $credentials = $this->_getSftpCredentials();
558
+ try {
559
+ $sftpDumpFile = new Varien_Io_Sftp();
560
+ $sftpDumpFile->open(
561
+ $credentials
562
+ );
563
+ $rootDir = Shipperhq_Pbint_Model_Credentials::getSftpCatalogDirectory();
564
+ if (!$this->_endsWith($rootDir, '/'))
565
+ $rootDir = $rootDir . '/';
566
+ $processedDir = $rootDir . 'outbound';
567
+ $sftpDumpFile->cd($processedDir);
568
+ $files = $sftpDumpFile->ls();
569
+
570
+ $exportedFiles = $this->_getLastExportedFileNames();
571
+ if (!$exportedFiles)
572
+ return;
573
+ foreach ($files as $file) {
574
+ foreach ($exportedFiles as $exportedFile) {
575
+ $fileNameWithoutExtension = str_replace(".gpg", "", str_replace(".csv", "", $exportedFile));
576
+ if ($this->_startsWith($file['text'], $fileNameWithoutExtension)) {
577
+ $dest = $notificationDir . '/' . $file['text'];
578
+ $sftpDumpFile->read($file['text'], $dest);
579
+ }
580
+ }
581
+
582
+ }
583
+ $sftpDumpFile->close();
584
+ } catch (Exception $e) {
585
+ if ($this->_debug) {
586
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint',
587
+ 'Pb Module could not connect to sftp server: ',
588
+ $credentials['host'], $e->getMessage());
589
+ }
590
+ return;
591
+ }
592
+
593
+ }
594
+
595
+ private function _encryptExportedFiles($exportedFiles)
596
+ {
597
+ $encryptedFiles = array();
598
+ $publicKey = Shipperhq_Pbint_Model_Credentials::getPublicKey();
599
+ if (!isset($publicKey) || $publicKey == '') {
600
+ if ($this->_debug) {
601
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint',
602
+ 'EncryptExportedFiles', 'Public key is not set cannot encrypt catalog files.');
603
+ }
604
+ return $exportedFiles;
605
+ }
606
+ try {
607
+ $gnupg = new gnupg();
608
+ $keyInfo = $gnupg->import($publicKey);
609
+ $gnupg->addencryptkey($keyInfo['fingerprint']);
610
+ $tmpDir = $this->_getTempDir();
611
+ if ($this->_debug) {
612
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint', 'EncryptExportedFiles', 'Encrypting the files.');
613
+ }
614
+ foreach ($exportedFiles as $exportedFile) {
615
+ $fileName = $tmpDir . $exportedFile;
616
+ if (is_dir($fileName))
617
+ continue;
618
+ $encryptedFileName = $exportedFile . '.gpg';
619
+ if ($this->_debug) {
620
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint', 'EncryptExportedFiles', 'Encrypted file' . $encryptedFileName);
621
+ }
622
+ file_put_contents($tmpDir . $encryptedFileName, $gnupg->encrypt(file_get_contents($fileName)));
623
+ $encryptedFiles[] = $encryptedFileName;
624
+ }
625
+ return $encryptedFiles;
626
+ } catch (Exception $e) {
627
+ if ($this->_debug) {
628
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint', 'Error in encryption', $e->getTraceAsString());
629
+ }
630
+ return $encryptedFiles;
631
+ }
632
+
633
+
634
+ }
635
+
636
+ public function upload()
637
+ {
638
+ $this->_debug = Mage::helper('shipperhq_pbint')->isDebug();
639
+
640
+ $tmpDir = $this->_getTempDir();
641
+ $exportedFiles = array_diff(scandir($tmpDir), array('..', '.'));
642
+ if (count($this->productIds) == 0) {
643
+ // No new products to send, don't send anything.
644
+ $this->_removeExportedFiles($exportedFiles);
645
+ return;
646
+ }
647
+ if ($this->_debug) {
648
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint', 'upload', 'Pb catalog file upload started for ' .count($this->productIds) .' products');
649
+ }
650
+ try {
651
+
652
+ if (Shipperhq_Pbint_Model_Credentials::isEncryptionEnabled()) {
653
+ $exportedFiles = $this->_encryptExportedFiles($exportedFiles);
654
+ } else {
655
+ if ($this->_debug) {
656
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint', 'upload',
657
+ 'Encryption is not enabled.' . Shipperhq_Pbint_Model_Credentials::isEncryptionEnabled());
658
+ }
659
+ }
660
+ $sftpDumpFile = new Varien_Io_Sftp();
661
+ $credentials = $this->_getSftpCredentials();
662
+
663
+ if ($this->_debug) {
664
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint', 'upload', $credentials);
665
+ }
666
+ $sftpDumpFile->open(
667
+ $credentials
668
+ );
669
+ //Upload to SFTP
670
+ $rootDir = Shipperhq_Pbint_Model_Credentials::getSftpCatalogDirectory();
671
+ if (!$this->_endsWith($rootDir, '/'))
672
+ $rootDir = $rootDir . '/';
673
+ $tmpSFTPDir = $rootDir . 'tmp';
674
+ $inboundDir = $rootDir . 'inbound';
675
+ $uploadedFiles = array();
676
+ foreach ($exportedFiles as $exportedFile) {
677
+ $fileName = $tmpDir . $exportedFile;
678
+ if (is_dir($fileName))
679
+ continue;
680
+
681
+ if ($this->_debug) {
682
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint', 'upload', 'CD to ' . $tmpSFTPDir);
683
+ }
684
+ $sftpDumpFile->cd($tmpSFTPDir);
685
+ if ($this->_debug) {
686
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint', 'upload', 'Uploading: ' . $fileName);
687
+ }
688
+ $writeOutcome = $sftpDumpFile->write($exportedFile, file_get_contents($fileName));
689
+
690
+ if($writeOutcome) {
691
+ if ($this->_debug) {
692
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint', 'upload', 'File upload outcome was ' . $writeOutcome
693
+ . " - now moving " . $tmpSFTPDir . "/$exportedFile" . " to " . $inboundDir . "/$exportedFile");
694
+ }
695
+ $sftpDumpFile->mv($tmpSFTPDir . "/$exportedFile", $inboundDir . "/$exportedFile");
696
+ $uploadedFiles[] = $exportedFile;
697
+ }
698
+ else {
699
+ if ($this->_debug) {
700
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint', 'upload', 'File upload outcome was ' . $writeOutcome
701
+ . ' Unable to write file' . $tmpSFTPDir . "/$exportedFile");
702
+ }
703
+ }
704
+ }
705
+ $sftpDumpFile->close();
706
+
707
+ } catch (Exception $e) {
708
+ if ($this->_debug) {
709
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint', 'Could not connect to Pitne Bowes sftp server: ',
710
+ $credentials['host'] . $e->getMessage());
711
+ }
712
+ $message = 'Could not connect to Pitney Bowes sftp server:' .$e->getMessage();
713
+ return $message;
714
+ }
715
+
716
+ if ($this->_debug) {
717
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint', 'upload',
718
+ 'Pb catalog file upload ended');
719
+ }
720
+
721
+ $this->_removeExportedFiles($exportedFiles);
722
+ $this->updateLastProductUpload();
723
+ $this->_logExportedFileInDB($uploadedFiles);
724
+ return true;
725
+ }
726
+
727
+ private function _getExportedFilesVariable()
728
+ {
729
+ $collection = Mage::getModel("shipperhq_pbint/variable")->getCollection();
730
+ $exportedFilesVariable = null;
731
+ foreach ($collection as $variable) {
732
+
733
+ if ($variable->getName() == "exportedFiles") {
734
+ $exportedFilesVariable = $variable;
735
+ break;
736
+ }
737
+
738
+ }
739
+ return $exportedFilesVariable;
740
+ }
741
+
742
+ private function _getLastExportedFileNames()
743
+ {
744
+ $exportedFilesVariable = $this->_getExportedFilesVariable();
745
+ if (!isset($exportedFilesVariable))
746
+ return false;
747
+ $exportedFiles = explode('|', $exportedFilesVariable->getValue());
748
+ return $exportedFiles;
749
+ }
750
+
751
+ private function _logExportedFileInDB($exportedFiles)
752
+ {
753
+ $strExportedFiles = implode('|', $exportedFiles);
754
+ $exportedFilesVariable = $this->_getExportedFilesVariable();
755
+ if (!isset($exportedFilesVariable)) {
756
+ $exportedFilesVariable = Mage::getModel("shipperhq_pbint/variable");
757
+ $exportedFilesVariable->setName("exportedFiles");
758
+ }
759
+
760
+ $exportedFilesVariable->setValue($strExportedFiles);
761
+ $exportedFilesVariable->save();
762
+ }
763
+
764
+ private function _startsWith($haystack, $needle)
765
+ {
766
+ // search backwards starting from haystack length characters from the end
767
+ return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
768
+ }
769
+
770
+ private function _endsWith($haystack, $needle)
771
+ {
772
+ // search forward starting from end minus needle length characters
773
+ return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE);
774
+ }
775
+
776
+ private function _removeExportedFiles($exportedFiles)
777
+ {
778
+ $tmpDir = $this->_getTempDir();
779
+ foreach ($exportedFiles as $exportedFile) {
780
+ $fileName = $tmpDir . $exportedFile;
781
+ if (is_dir($fileName))
782
+ continue;
783
+ unlink($fileName);
784
+ $fileName = str_replace(".gpg", "", $fileName); //remove unencrypted file
785
+ if (is_file($fileName))
786
+ unlink($fileName);
787
+ }
788
+ }
789
+
790
+
791
+ /**
792
+ * @param Shipperhq_Pbint_Model_Catalog_Product $product
793
+ * @param string $categoryCode
794
+ */
795
+ private function writeProduct($product, $categoryCode, $parentSku, $category)
796
+ {
797
+ if ($product->shouldUpload($this->lastDiff)) {
798
+ array_push($this->productIds, $product->getMageProduct()->getId());
799
+ $product->writeToFile($this->file, $categoryCode, $parentSku, $category);
800
+ fflush($this->file);
801
+ }
802
+ }
803
+
804
+ public static function stripHtml($text)
805
+ {
806
+ return preg_replace("/<\s*\/\s*\w\s*.*?>|<\s*br\s*>/", '', preg_replace("/<\s*\w.*?>/", '', $text));
807
+ }
808
+
809
+ /**
810
+ * Loads products without categories and logs them in log file
811
+ */
812
+ public function logProdWithoutCategories()
813
+ {
814
+ $productCollection = Mage::getResourceModel('catalog/product_collection')
815
+ ->setStoreId(0)
816
+ ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
817
+ ->addAttributeToFilter('category_id', array('null' => true))
818
+ ->addAttributeToSelect('*');
819
+
820
+
821
+ $productCollection->getSelect()->group('product_id')->distinct(true);
822
+
823
+ $productCollection->load();
824
+ $skus = '';
825
+ foreach ($productCollection as $product) {
826
+ $skus = $skus . $product->getSku() . ",";
827
+
828
+ }
829
+ if (Mage::helper('shipperhq_pbint')->isDebug()) {
830
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint', 'Products without categories:',
831
+ $skus);
832
+ }
833
+ }
834
+
835
+ /**
836
+ * @return array
837
+ */
838
+ private function _getSftpCredentials()
839
+ {
840
+ $credentials = array(
841
+ 'host' => Shipperhq_Pbint_Model_Credentials::getSftpHostname(),
842
+ "port" => Shipperhq_Pbint_Model_Credentials::getSftpPort(),
843
+ 'username' => Shipperhq_Pbint_Model_Credentials::getSftpUsername(),
844
+ 'password' => Shipperhq_Pbint_Model_Credentials::getSftpPassword(),
845
+ 'timeout' => '10'
846
+ );
847
+ return $credentials;
848
+ }
849
+
850
+ /**
851
+ * @param $part
852
+ */
853
+ private function _stripPartFromFileName($part)
854
+ {
855
+ if ($part > 0) {
856
+ //there is only one part remove part1 from filename
857
+ rename($this->filename, str_replace('_part1', '', $this->filename));
858
+ }
859
+ }
860
+ }
861
+
862
+ ?>
app/code/community/Shipperhq/Pbint/Model/Catalog/Product.php ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Pitney Bowes International
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Class Shipperhq_Pbint_Model_Catalog_Product
33
+ *
34
+ */
35
+ class Shipperhq_Pbint_Model_Catalog_Product
36
+ {
37
+ /*@var $product Mage_Catalog_Model_Product */
38
+ protected $product;
39
+ protected $_productUrl;
40
+
41
+
42
+ public function __construct($product, $url = null)
43
+ {
44
+ $id = $product;
45
+ if (gettype($product) == "object" && $id instanceOf Mage_Catalog_Model_Product) {
46
+ $this->product = $product;
47
+ } else
48
+ $this->product = Mage::getModel('catalog/product')->load($id);
49
+ $this->_productUrl = $url;
50
+ }
51
+
52
+ /**
53
+ * Created by BigPixel 6/15/2012
54
+ * @return Mage_Catalog_Model_Product
55
+ */
56
+ public function getMageProduct()
57
+ {
58
+ return $this->product;
59
+ }
60
+
61
+ /**
62
+ * @return string
63
+ */
64
+ public function getSKU()
65
+ {
66
+ return $this->product->getSku();
67
+ }
68
+
69
+ public function getPrice()
70
+ {
71
+ return $this->product->getPrice();
72
+ }
73
+
74
+ public function getUPC()
75
+ {
76
+ }
77
+
78
+ /**
79
+ * @return string
80
+ */
81
+ public function getURL()
82
+ {
83
+ if ($this->_productUrl)
84
+ return $this->_productUrl;
85
+ return $this->product->getProductUrl();
86
+ }
87
+
88
+ /**
89
+ * @return int
90
+ * Gets the id of the category that is direct parent of the product
91
+ */
92
+ public function getCategoryCode()
93
+ {
94
+ $categories = $this->product->getCategoryCollection();
95
+
96
+ $maxDepth = -1;
97
+ $finalCategory = null;
98
+ foreach ($categories as $category) {
99
+ $pathComponents = explode("/", $category->getPath());
100
+ if (count($pathComponents) > $maxDepth) {
101
+ $finalCategory = $category;
102
+ $maxDepth = count($pathComponents);
103
+ }
104
+ }
105
+ return $finalCategory->getId();
106
+ }
107
+
108
+ /**
109
+ * @return string
110
+ *
111
+ */
112
+ public function getCountryOfOrigin()
113
+ {
114
+ return $this->product->getCountryOfManufacture(); //added by kamran,1/14/2012
115
+ }
116
+
117
+ /**
118
+ * @return string
119
+ */
120
+ public function getDescription()
121
+ {
122
+ return utf8_encode($this->product->getDescription());
123
+ }
124
+
125
+ public function getShortDescription()
126
+ {
127
+ return utf8_encode($this->product->getShortDescription());
128
+ }
129
+
130
+ /**
131
+ * @return string
132
+ */
133
+ public function getName()
134
+ {
135
+ return utf8_encode($this->product->getName());
136
+ }
137
+
138
+ /**
139
+ * @return flaot
140
+ */
141
+ public function getWeight()
142
+ {
143
+ return $this->product->getWeight();
144
+ }
145
+
146
+ public function getSize()
147
+ {
148
+ }
149
+
150
+ /**
151
+ * @param $file
152
+ * @param $categoryCode
153
+ * Write this product into the xml file
154
+ */
155
+ public function writeToFile($file, $categoryCode, $parentSku, $category)
156
+ {
157
+ /** $categoryCode is passed in method because we don't have categoryCode for child products. BigPixel 6/11/2012 */
158
+ $name = Shipperhq_Pbint_Model_Catalog_File::stripHtml($this->getName());
159
+ $name = preg_replace("/[,.\-\+=;:\\(){}\[\]@?%$#]/", '', $name);
160
+ $string = "<Commodity>\n";
161
+ $string .= "<CategoryCode><![CDATA[" . htmlentities($categoryCode) . "]]></CategoryCode>\n";
162
+ $string .= "<SKU><![CDATA[" . htmlentities($this->getSKU()) . "]]></SKU>\n";
163
+ $string .= "<Name><![CDATA[" . htmlentities($name) . "]]></Name>\n";
164
+ $string .= "<CountryOfOrigin><![CDATA[" . htmlentities(preg_replace("/[^A-Za-z0-9]/", '', $this->getCountryOfOrigin())) . "]]></CountryOfOrigin>\n"; //added by kamran,1/14/2012
165
+ $description = Shipperhq_Pbint_Model_Catalog_File::stripHtml($this->getDescription());
166
+ $description = preg_replace("/[,.\-\+=;:\\(){}\[\]@?%$#]/", '', $description);
167
+ if (strlen($description) >= 2000) {
168
+
169
+ $description = $this->chopString($description, 1999);
170
+ }
171
+
172
+ $shortDescription = Shipperhq_Pbint_Model_Catalog_File::stripHtml($this->getShortDescription());
173
+ $shortDescription = preg_replace("/[,.\-\+=;:\\(){}\[\]@?%$#]/", '', $shortDescription);
174
+ if (strlen($shortDescription) >= 2000) {
175
+
176
+ $shortDescription = $this->chopString($shortDescription, 1999);
177
+ }
178
+ $string .= "<Description><![CDATA[" . $description . "]]></Description>\n";
179
+ $string .= "<URL><![CDATA[" . htmlentities($this->getURL()) . "]]></URL>\n";
180
+
181
+ if ($this->getWeight() != null) {
182
+ $string .= "<Size><Weight><![CDATA[" . $this->getWeight() . "]]></Weight><Source><![CDATA[" . Shipperhq_Pbint_Model_Credentials::getMerchantCode() . "]]></Source></Size>\n";
183
+ }
184
+ $string .= "</Commodity>\n";
185
+ // fputcsv($this->file,array('MERCHANT_COMMODITY_REF_ID','COMMODITY_NAME_TITLE','SHORT_DESCRIPTION',
186
+ // 'LONG_DESCRIPTION','RETAILER_ID','COMMODITY_URL','RETAILER_UNIQUE_ID','PCH_CATEGORY_ID',
187
+ // 'RH_CATEGORY_ID','STANDARD_PRICE','WEIGHT_UNIT','DISTANCE_UNIT','COO','IMAGE_URL','PARENT_SKU',
188
+ // 'CHILD_SKU','PARCELS_PER_SKU','UPC','UPC_CHECK_DIGIT','GTIN','MPN','ISBN','BRAND','MANUFACTURER',
189
+ // 'MODEL_NUMBER','MANUFACTURER_STOCK_NUMBER','COMMODITY_CONDITION','COMMODITY_HEIGHT',
190
+ // 'COMMODITY_WIDTH','COMMODITY_LENGTH','PACKAGE_WEIGHT','PACKAGE_HEIGHT','PACKAGE_WIDTH',
191
+ // 'PACKAGE_LENGTH','HAZMAT','ORMD','CHEMICAL_INDICATOR','PESTICIDE_INDICATOR','AEROSOL_INDICATOR',
192
+ // 'RPPC_INDICATOR','BATTERY_TYPE','NON_SPILLABLE_BATTERY','FUEL_RESTRICTION','SHIP_ALONE',
193
+ // 'RH_CATEGORY_ID_PATH','RH_CATEGORY_NAME_PATH','RH_CATEGORY_URL_PATH','GPC','COMMODITY_WEIGHT',
194
+ // 'HS_CODE','CURRENCY'));
195
+ $merchantCode = Shipperhq_Pbint_Model_Credentials::getMerchantCode();
196
+ fputcsv($file, array($this->getSKU(), $name, $shortDescription,
197
+ $description, $merchantCode, $this->getURL(), $merchantCode, '',
198
+ $categoryCode, $this->getPrice(), 'lb', '', $this->getCountryOfOrigin(), '', '',
199
+ '', '', '', '', '', '', '', '', '',
200
+ '', '', '', '',
201
+ '', '', $this->getWeight(), '', '',
202
+ '', '', '', '', '', '',
203
+ '', '', '', '', '',
204
+ strval($category->getData('id_path')), $category->getData('name_path')
205
+ //,'','','','',$category->getData('store')->getCurrentCurrencyCode()
206
+ ));
207
+ //fwrite($file, $string);
208
+ }
209
+
210
+ /**
211
+ * @param $lastDiff
212
+ * @return bool
213
+ * Checks whether we need to upload this product or not
214
+ */
215
+ public function shouldUpload($lastDiff)
216
+ {
217
+ $lastUpload = $this->product->getPbPbgspUpload();
218
+
219
+ if (!$lastUpload) {
220
+ // First upload.
221
+ return true;
222
+ } else if ($lastDiff <= $lastUpload - (30 * 60)) {
223
+ // Added after the last diff
224
+ return true;
225
+ } else {
226
+ return false;
227
+ }
228
+ }
229
+
230
+ public function chopString($str, $len)
231
+ {
232
+ $end = $len;
233
+ $lastFour = substr($str, $end - strlen("&amp"), strlen("&amp"));
234
+ $pos = strpos($lastFour, "&");
235
+ if (!($pos === FALSE)) {
236
+ $end = $end - strlen("&amp") + $pos;
237
+ }
238
+ $ret = substr($str, 0, $end);
239
+ return $ret;
240
+ }
241
+
242
+ }
243
+
244
+ ?>
app/code/community/Shipperhq/Pbint/Model/Credentials.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Pitney Bowes International
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+ class Shipperhq_Pbint_Model_Credentials {
31
+
32
+ public static function decrypt($string) {
33
+ if (!empty($string)) {
34
+ return Mage::helper('core')->decrypt($string);
35
+ }
36
+ return "";
37
+ }
38
+
39
+ public static function getMaxRecordsCount() {
40
+ return Mage::getStoreConfig('shipperhqpitney/shqpbint/catalog_size');
41
+ }
42
+ public static function getAdminEmail() {
43
+ return Mage::getStoreConfig('shipperhqpitney/shqpbint/admin_email');
44
+ }
45
+ public static function getCatalogSenderID() {
46
+ return Mage::getStoreConfig('shipperhqpitney/shqpbint/catalog_sender_id');
47
+ }
48
+
49
+ public static function getMerchantCode() {
50
+ return self::decrypt(Mage::getStoreConfig('shipperhqpitney/shqpbint/merchantcode'));
51
+ }
52
+
53
+ public static function getSftpUsername() {
54
+ return self::decrypt(Mage::getStoreConfig('shipperhqpitney/shqpbint/ftpuser'));
55
+ }
56
+ public static function getSftpPassword() {
57
+ return self::decrypt(Mage::getStoreConfig('shipperhqpitney/shqpbint/ftppass'));
58
+ }
59
+ public static function getSftpHostname() {
60
+ return Mage::getStoreConfig('shipperhqpitney/shqpbint/ftphost');
61
+ }
62
+ public static function getSftpPort() {
63
+ return Mage::getStoreConfig('shipperhqpitney/shqpbint/ftpport');
64
+ }
65
+ public static function getSftpCatalogDirectory() {
66
+ return self::decrypt(Mage::getStoreConfig('shipperhqpitney/shqpbint/ftpdir'));
67
+ }
68
+ public static function isEncryptionEnabled() {
69
+ return Mage::getStoreConfig('shipperhqpitney/shqpbint/catalog_encryption_enabled');
70
+ }
71
+ public static function getPublicKey() {
72
+ return Mage::getStoreConfig('shipperhqpitney/shqpbint/encryption_public_key');
73
+ }
74
+ public static function getPBID() {
75
+ return "16061";
76
+ }
77
+ }
78
+ ?>
app/code/community/Shipperhq/Pbint/Model/Creditmemo/Duty.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Creditmemo_Duty extends Mage_Sales_Model_Order_Creditmemo_Total_Tax
32
+ {
33
+ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
34
+ {
35
+
36
+ $creditmemo->setShqPbDutyAmount(0);
37
+ $creditmemo->setBaseShqPbDutyAmount(0);
38
+
39
+ $prevCreditmemoDutyAmount = 0;
40
+ $prevBaseCreditmemoDutyAmount = 0;
41
+
42
+ foreach ($creditmemo->getOrder()->getCreditmemosCollection() as $prevCreditmemo) {
43
+ if ($prevCreditmemo->getShqPbDutyAmount() && ($prevCreditmemo->getState() != Mage_Sales_Model_Order_Creditmemo::STATE_CANCELED)) {
44
+ $prevCreditmemoDutyAmount += $prevCreditmemo->getShqPbDutyAmount();
45
+ $prevBaseCreditmemoDutyAmount += $prevCreditmemo->getBaseShqPbDutyAmount();
46
+ }
47
+ }
48
+
49
+ $allowedAmount = $creditmemo->getOrder()->getShqPbDutyAmount() - $prevCreditmemoDutyAmount;
50
+ $baseAllowedAmount = $creditmemo->getOrder()->getBaseShqPbDutyAmount() - $prevBaseCreditmemoDutyAmount;
51
+
52
+ $creditmemoIsLast = true;
53
+ foreach ($creditmemo->getAllItems() as $item) {
54
+ $orderItem = $item->getOrderItem();
55
+ if ($orderItem->isDummy()) {
56
+ continue;
57
+ }
58
+
59
+ if (!$item->isLast()) {
60
+ $creditmemoIsLast = false;
61
+ break;
62
+ }
63
+ }
64
+
65
+ if ($creditmemoIsLast) {
66
+ $creditmemo->setShqPbDutyAmount($allowedAmount);
67
+ $creditmemo->setBaseShqPbDutyAmount($baseAllowedAmount);
68
+
69
+ $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $allowedAmount);
70
+ $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseAllowedAmount);
71
+ }
72
+
73
+ return $this;
74
+ }
75
+ }
app/code/community/Shipperhq/Pbint/Model/Helper.php ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Helper extends Mage_Core_Model_Abstract
32
+ {
33
+
34
+ public function processReserveOrderResponse($response)
35
+ {
36
+ if($response) {
37
+ $errors = (array)$response->errors;
38
+ $responseSummary = (array)$response->responseSummary;
39
+ if(($errors && count($errors) > 0) || $responseSummary['status'] != 1) {
40
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
41
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_PbInt', 'Shipper HQ could not reserve the order',
42
+ $errors, $responseSummary);
43
+ }
44
+ //Mage::throwException("Unable to create Pb order.");
45
+ return false;
46
+ }
47
+
48
+ $orderId = $response->orderId;
49
+ $shipToHub = (array)$response->shipToHub;
50
+ $rateInformation = (array)$response->carrierRate;
51
+ if(empty($shipToHub) || empty($rateInformation) || $orderId == 'Not Set') {
52
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
53
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_PbInt', 'Shipper HQ did not return Pitney International duties information for order',
54
+ $response);
55
+ }
56
+ return false;
57
+ }
58
+ if($rateInformation && isset($rateInformation['rates']) && isset($rateInformation['rates'][0])) {
59
+ $rate = $rateInformation['rates'][0];
60
+ Mage::getSingleton("customer/session")->setPbDutyAndTax($rate->customDuties);
61
+ }
62
+ $orderNumber = Mage::getModel("shipperhq_pbint/ordernumber");
63
+ $hubAddress = $shipToHub['address'];
64
+ $orderNumber->setCpOrderNumber($orderId);
65
+ $orderNumber->setHubId($shipToHub['hubId']);
66
+ $orderNumber->setHubStreet1($hubAddress->street);
67
+ $orderNumber->setHubStreet2($hubAddress->street2);
68
+ $orderNumber->setHubProvinceOrState($hubAddress->region);
69
+ $orderNumber->setHubCity($hubAddress->city);
70
+ $orderNumber->setHubPostcode($hubAddress->zipcode);
71
+ $orderNumber->setHubCountry($hubAddress->country);
72
+
73
+ Mage::getSingleton("customer/session")->setPbOrderNumber($orderNumber);
74
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
75
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_PbInt',
76
+ 'Shipper HQ Pitney International reserve order successful',
77
+ "Order ID: " .$orderId);
78
+ }
79
+ return true;
80
+ }
81
+
82
+ }
83
+ /*
84
+ * Determine whether this shipment requires processing to generate ASN
85
+ */
86
+ public function analyzeProcessShipment($shipment)
87
+ {
88
+ $processRequired = false;
89
+
90
+ $order = $shipment->getOrder();
91
+ /* @var $order Mage_Sales_Model_Order */
92
+
93
+ if(Mage::helper('shipperhq_pbint')->isPbOrder($order->getCarrierType())) {
94
+ $processRequired = true;
95
+ }
96
+ $parcel = Mage::getModel("shipperhq_pbint/inboundparcel")-> getCollection();
97
+ $parcel->addFieldToFilter('mage_order_number', $order->getRealOrderId());
98
+ if(count($parcel) > 0) {
99
+ if (Mage::helper('shipperhq_pbint')->isDebug()) {
100
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
101
+ 'Processing shipment', 'Inbound parcel already created for this order');
102
+ }
103
+ $processRequired = false;
104
+ }
105
+
106
+ return $processRequired;
107
+
108
+ }
109
+
110
+ public function processShipmentAddonResponse($shipment, $response, $pitneyOrderId)
111
+ {
112
+ try {
113
+
114
+ if($response) {
115
+ $errors = (array)$response->errors;
116
+ $responseSummary = (array)$response->responseSummary;
117
+ if(($errors && count($errors) > 0) || $responseSummary['status'] != 1) {
118
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
119
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_PbInt', 'Shipper HQ could create ASN for Pitney order',
120
+ $errors, $responseSummary);
121
+ }
122
+ return false;
123
+ }
124
+ $orderID = $shipment->getOrder()->getRealOrderId();
125
+ if(!isset($response->parcelId)) {
126
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
127
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_PbInt', 'Shipper HQ inbound parcel response.',
128
+ 'No parcel ID returned for orderID' .$orderID . ', Pitney Order ID: ' .$pitneyOrderId .' with response: ' .$response);
129
+ }
130
+ return;
131
+ }
132
+ $pitneyParcel = Mage::getModel('shipperhq_pbint/inboundparcel');
133
+ $pitneyParcel->setInboundParcel($response->parcelId);
134
+ $pitneyParcel->setMageOrderNumber($orderID);
135
+ $pitneyParcel->setPbOrderNumber( $pitneyOrderId);
136
+ $pitneyParcel->save();
137
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
138
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_PbInt', 'Shipper HQ created inbound parcel ID.',
139
+ 'Magento Order ID: ' .$orderID . ', Pitney Order ID: ' .$pitneyOrderId .' with ASN: ' .$response->parcelId);
140
+ }
141
+
142
+
143
+ }
144
+ }
145
+ catch(Exception $e) {
146
+ if (Mage::helper('shipperhq_pbint')->isDebug()) {
147
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint',
148
+ 'Error creating inbound parcel.', $e->getMessage());
149
+ }
150
+ Mage::logException($e);
151
+ }
152
+ }
153
+
154
+ public function confirmOrderRequired($magentoOrderNumber)
155
+ {
156
+ Mage::getSingleton("customer/session")->setPbDutyAndTax(0);
157
+ $orderNumber = Mage::getSingleton("customer/session")->getPbOrderNumber();
158
+
159
+ if($orderNumber) {
160
+ $orderNumber->setMageOrderNumber($magentoOrderNumber);
161
+ $orderNumber->setConfirmed(false);
162
+ $orderNumber->setReferenced(false);
163
+ $orderNumber->save();
164
+ if (Mage::helper('shipperhq_pbint')->isDebug()) {
165
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
166
+ 'Confirm order required with ShipperHQ Pitney for', $magentoOrderNumber.'. Hub ID: '
167
+ .$orderNumber->getHubId() . ', Hub country: ' . $orderNumber->getHubCountry());
168
+ }
169
+ Mage::getSingleton("customer/session")->setPbOrderNumber($orderNumber);
170
+ return $orderNumber->getData('cp_order_number');
171
+ }
172
+ return false;
173
+ }
174
+
175
+ public function processConfirmOrderResponse($response)
176
+ {
177
+ $pbOrder = Mage::getSingleton("customer/session")->getPbOrderNumber();
178
+
179
+ if(!is_object($response)) {
180
+ if (Mage::helper('shipperhq_pbint')->isDebug()) {
181
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint',
182
+ 'Confirm Order did not return a response', $response);
183
+ }
184
+ return;
185
+ }
186
+
187
+ $errors = (array)$response->errors;
188
+ $responseSummary = (array)$response->responseSummary;
189
+ $result = isset($response->result) ? (array)$response->result : false;
190
+ if(($errors && count($errors) > 0) || $responseSummary['status'] != 1) {
191
+ if (Mage::helper('shipperhq_pbint')->isDebug()) {
192
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint',
193
+ 'Error confirming order', $response);
194
+ }
195
+ }
196
+ elseif(in_array('SUCCCESS', $result)) {
197
+ try {
198
+ $pbOrder->setConfirmed(true);
199
+ $pbOrder->setReferenced(true);
200
+ $pbOrder->save();
201
+ if (Mage::helper('shipperhq_pbint')->isDebug()) {
202
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
203
+ 'Confirmed order for ShipperHQ Pitney Bowes', $pbOrder->getData('mage_order_number'));
204
+ }
205
+ }
206
+ catch(Exception $e) {
207
+ if (Mage::helper('shipperhq_pbint')->isDebug()) {
208
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Pbint',
209
+ 'Confirm order response processing, error', $e->getMessage());
210
+ }
211
+ }
212
+ }
213
+ }
214
+
215
+ /*
216
+ * reset session saved variables
217
+ */
218
+ public function cleanDownSession()
219
+ {
220
+ Mage::getSingleton("customer/session")->setPbDutyAndTax(false);
221
+ Mage::getSingleton("customer/session")->setPbOrderNumber(false);
222
+
223
+ }
224
+ }
app/code/community/Shipperhq/Pbint/Model/Inboundparcel.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Inboundparcel extends Mage_Core_Model_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ parent::_construct();
36
+ $this->_init('shipperhq_pbint/inboundparcel');
37
+ }
38
+ }
39
+
40
+ ?>
app/code/community/Shipperhq/Pbint/Model/Invoice/Duty.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Invoice_Duty extends Mage_Sales_Model_Order_Invoice_Total_Tax
32
+ {
33
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
34
+ {
35
+ if (Mage::helper('shipperhq_pbint')->isDebug()) {
36
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
37
+ 'Shipperhq_Pbint_Model_Invoice_Duty', 'collect function');
38
+ }
39
+ $invoice->setShqPbDutyAmount(0);
40
+ $invoice->setBaseShqPbDutyAmount(0);
41
+
42
+ // Get any amount we've invoiced already
43
+ $prevInvoiceDutyAmount = 0;
44
+ $prevBaseInvoiceDutyAmount = 0;
45
+ foreach ($invoice->getOrder()->getInvoiceCollection() as $prevInvoice) {
46
+ if ($prevInvoice->getShqPbDutyAmount() && !$prevInvoice->isCanceled()) {
47
+ $prevInvoiceDutyAmount += $prevInvoice->getShqPbDutyAmount();
48
+ $prevBaseInvoiceDutyAmount += $prevInvoice->getBaseShqPbDutyAmount();
49
+ }
50
+ }
51
+
52
+ $dutyAmount = 0;
53
+ $baseDutyAmount = 0;
54
+ $invoiceIsLast = true;
55
+ foreach ($invoice->getAllItems() as $item) {
56
+ $orderItem = $item->getOrderItem();
57
+ if ($orderItem->isDummy()) {
58
+ continue;
59
+ }
60
+
61
+ if (!$item->isLast()) {
62
+ $invoiceIsLast = false;
63
+ }
64
+
65
+ }
66
+ if ($invoiceIsLast) {
67
+ $dutyAmount = $invoice->getOrder()->getShqPbDutyAmount() - $prevInvoiceDutyAmount;
68
+ $baseDutyAmount = $invoice->getOrder()->getBaseShqPbDutyAmount() - $prevBaseInvoiceDutyAmount;
69
+ }
70
+
71
+ $invoice->setShqPbDutyAmount($dutyAmount);
72
+ $invoice->setBaseShqPbDutyAmount($baseDutyAmount);
73
+
74
+ $invoice->setGrandTotal($invoice->getGrandTotal() + $dutyAmount);
75
+ $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseDutyAmount);
76
+
77
+ return $this;
78
+ }
79
+ }
app/code/community/Shipperhq/Pbint/Model/Mysql4/Inboundparcel.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Mysql4_Inboundparcel extends Mage_Core_Model_Mysql4_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ $this->_init('shipperhq_pbint/inboundparcel', 'inbound_parcel_id');
36
+ }
37
+ }
38
+
39
+ ?>
app/code/community/Shipperhq/Pbint/Model/Mysql4/Inboundparcel/Collection.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Mysql4_Inboundparcel_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ $this->_init('shipperhq_pbint/inboundparcel');
36
+ }
37
+ }
38
+
39
+ ?>
app/code/community/Shipperhq/Pbint/Model/Mysql4/Ordernumber.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Mysql4_Ordernumber extends Mage_Core_Model_Mysql4_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ $this->_init('shipperhq_pbint/ordernumber', 'ordernumber_id');
36
+ }
37
+ }
38
+
39
+ ?>
app/code/community/Shipperhq/Pbint/Model/Mysql4/Ordernumber/Collection.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Mysql4_Ordernumber_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ $this->_init('shipperhq_pbint/ordernumber');
36
+ }
37
+ }
38
+
39
+ ?>
app/code/community/Shipperhq/Pbint/Model/Mysql4/Variable.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Mysql4_Variable extends Mage_Core_Model_Mysql4_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ $this->_init('shipperhq_pbint/variable', 'variable_id');
36
+ }
37
+ }
38
+
39
+ ?>
app/code/community/Shipperhq/Pbint/Model/Mysql4/Variable/Collection.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Mysql4_Variable_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ $this->_init('shipperhq_pbint/variable');
36
+ }
37
+ }
38
+
39
+ ?>
app/code/community/Shipperhq/Pbint/Model/Observer.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Observer extends Mage_Core_Model_Abstract
32
+ {
33
+ const MODULE_NAME = 'Shipperhq_Pbint';
34
+
35
+ public function addDutiesOnEstimation($observer)
36
+ {
37
+ Mage::getSingleton("customer/session")->setPbDutyAndTax(false);
38
+
39
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
40
+ $selectedMethod = null;
41
+ if ($quote->getShippingAddress()) {
42
+ $selectedMethod = $quote->getShippingAddress()->getShippingMethod();
43
+ }
44
+
45
+ if ($selectedMethod) {
46
+ $rate = $quote->getShippingAddress()->getShippingRateByCode($selectedMethod);
47
+ if($rate) {
48
+ if (Mage::helper('shipperhq_pbint')->isDebug()) {
49
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
50
+ 'Add duties on estimation', $rate->getMethod() . ' and tax' . $rate->getCustomDuties());
51
+ }
52
+ Mage::getSingleton("customer/session")->setPbDutyAndTax($rate->getCustomDuties());
53
+ }
54
+
55
+ }
56
+ }
57
+
58
+ public function modifyOrderView($observer = NULL)
59
+ {
60
+ if (!$observer) {
61
+ return;
62
+ }
63
+ if (Mage::getStoreConfig('advanced/modules_disable_output/' . self::MODULE_NAME))
64
+ return;
65
+ $transport = $observer->getEvent()->getTransport();
66
+ $layoutName = $observer->getEvent()->getBlock()->getNameInLayout();
67
+ if ('order_info' == $layoutName) {
68
+
69
+ $pitneyOrderNumber = $this->_getCpOrderNumber($observer->getEvent()->getBlock()->getOrder());
70
+ if ($pitneyOrderNumber) {
71
+ $html = "<div class='entry-edit'>
72
+ <div class='entry-edit-head'>
73
+ <h4 class='icon-head '>Pitney Bowes Shipments</h4>
74
+ </div>
75
+ <fieldset>
76
+ <strong>PB Order Number</strong>
77
+ <span>" . $pitneyOrderNumber->getCpOrderNumber() . "</span><br/>
78
+ <strong>Hub ID</strong>
79
+ <span>" . $pitneyOrderNumber->getHubId() . "</span><br/>
80
+ <strong>Hub Street 1</strong>
81
+ <span>" . $pitneyOrderNumber->getHubStreet1() . "</span><br/>
82
+ <strong>Hub Street 2</strong>
83
+ <span>" . $pitneyOrderNumber->getHubStreet2() . "</span><br/>
84
+ <strong>Hub City</strong>
85
+ <span>" . $pitneyOrderNumber->getHubCity() . "</span><br/>
86
+ <strong>Hub Province/State</strong>
87
+ <span>" . $pitneyOrderNumber->getHubProvinceOrState() . "</span><br/>
88
+ <strong>Hub Zip</strong>
89
+ <span>" . $pitneyOrderNumber->getHubPostcode() . "</span><br/>
90
+ <strong>Hub Country</strong>
91
+ <span>" . $pitneyOrderNumber->getHubCountry() . "</span><br/>
92
+ </fieldset>
93
+ </div>";
94
+ $transport['html'] = $transport['html'] . $html;
95
+ }
96
+
97
+
98
+
99
+ } else if ('email/order/shipment/track.phtml' == $observer->getEvent()->getBlock()->getTemplate()) {
100
+
101
+ $cpord = $this->_getCPORD($observer->getEvent()->getBlock()->getOrder());
102
+ if ($cpord) {
103
+ $staging = 0;
104
+ //TODO offer staging
105
+ $transport['html'] = "<a href='http://tracking.ecommerce.pb.com/track/$cpord?staging=$staging'>Track your order</a>";
106
+ }
107
+
108
+ } else if ('shipping.tracking.popup' == $layoutName) {
109
+
110
+ $helper = Mage::helper('shipping');
111
+ $data = $helper->decodeTrackingHash($observer->getEvent()->getBlock()->getRequest()->getParam('hash'));
112
+
113
+ $orderId = null;
114
+ if ($data['key'] == 'order_id')
115
+ $orderId = $data['id'];
116
+ else if ($data['key'] == 'ship_id') {
117
+ /* @var $model Mage_Sales_Model_Order_Shipment */
118
+ $model = Mage::getModel('sales/order_shipment');
119
+ $ship = $model->load($data['id']);
120
+ $orderId = $model->getOrderId();
121
+ } else if ($data['key'] == 'track_id') {
122
+ $track = Mage::getModel('sales/order_shipment_track')->load($data['id']);
123
+ $orderId = $track->getOrderId();
124
+ }
125
+ if (!$orderId)
126
+ return;
127
+ $cpord = $this->_getCPORD(Mage::getModel('sales/order')->load($orderId));
128
+ if ($cpord) {
129
+ $staging = 0;
130
+ //TODO offer staging
131
+ $script = "<script lang='javascript'>
132
+ window.location = 'http://tracking.ecommerce.pb.com/track/$cpord?staging=$staging';
133
+ </script>
134
+ ";
135
+ $transport['html'] = $script;
136
+ }
137
+
138
+ }
139
+ return $this;
140
+ }
141
+
142
+ private function _getCPORD($order)
143
+ {
144
+ if ($order) {
145
+ $cpOrder = $this->_getCpOrderNumber($order);
146
+ if ($cpOrder) {
147
+ return $cpOrder->getCpOrderNumber();
148
+ }
149
+
150
+ }
151
+
152
+ return false;
153
+ }
154
+
155
+ private function _getCpOrderNumber($order)
156
+ {
157
+ if ($order) {
158
+ $clearPathOrders = Mage::getModel("shipperhq_pbint/ordernumber")->getCollection();
159
+
160
+ $clearPathOrders->addFieldToFilter('mage_order_number', $order->getRealOrderId());
161
+ foreach ($clearPathOrders as $cpOrder) {
162
+ return $cpOrder;
163
+
164
+ }
165
+ }
166
+
167
+ return false;
168
+ }
169
+ }
170
+
171
+ ?>
app/code/community/Shipperhq/Pbint/Model/Ordernumber.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Ordernumber extends Mage_Core_Model_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ parent::_construct();
36
+ $this->_init('shipperhq_pbint/ordernumber');
37
+ }
38
+ }
39
+
40
+ ?>
app/code/community/Shipperhq/Pbint/Model/Pdf/Duty.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Pitney Bowes International
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+ class Shipperhq_Pbint_Model_Pdf_Duty extends Mage_Tax_Model_Sales_Pdf_Tax {
31
+ public function getTitle() {
32
+ $shipMethod = $this->getOrder()->getShippingMethod();
33
+ $len = strlen("pbint_");
34
+ if (strlen($shipMethod) > $len && substr($shipMethod,0,$len) == "pbint_") {
35
+ return "Importation Charges";
36
+ }
37
+ return parent::getTitle();
38
+ }
39
+ }
40
+
41
+ ?>
app/code/community/Shipperhq/Pbint/Model/Quote/Duty.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Pitney Bowes International
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+ class Shipperhq_Pbint_Model_Quote_Duty extends Mage_Sales_Model_Quote_Address_Total_Abstract
31
+ {
32
+ /**
33
+ * Discount calculation object
34
+ *
35
+ * @var Mage_SalesRule_Model_Validator
36
+ */
37
+ protected $dutyCalculated = false;
38
+ protected $dutyDisplayed = false;
39
+
40
+ public function __construct()
41
+ {
42
+ // parent::__construct();
43
+ $this->setCode('shq_pb_duty');
44
+
45
+ }
46
+
47
+ public function getDutyAndTax() {
48
+ return Mage::getSingleton("customer/session")->getPbDutyAndTax();
49
+ }
50
+
51
+ /**
52
+ * Collect address discount amount
53
+ *
54
+ * @param Mage_Sales_Model_Quote_Address $address
55
+ * @return Mage_SalesRule_Model_Quote_Discount
56
+ */
57
+ public function collect(Mage_Sales_Model_Quote_Address $address)
58
+ {
59
+ parent::collect($address);
60
+
61
+ if ($amount = $this->getDutyAndTax()) {
62
+ $items = $this->_getAddressItems($address);
63
+ if (!count($items)) {
64
+ return $this;
65
+ }
66
+
67
+ $this->_setAmount($address->getQuote()->getStore()->convertPrice($amount, false));
68
+ $this->_setBaseAmount($amount);
69
+ }
70
+ return $this;
71
+ }
72
+
73
+
74
+ /**
75
+ * Add discount total information to address
76
+ *
77
+ * @param Mage_Sales_Model_Quote_Address $address
78
+ * @return Mage_SalesRule_Model_Quote_Discount
79
+ */
80
+ public function fetch(Mage_Sales_Model_Quote_Address $address)
81
+ {
82
+ if ($address->getShqPbDutyAmount() != 0) {
83
+ $address->addTotal(array(
84
+ 'code' => $this->getCode(),
85
+ 'title' => 'International Duty',
86
+ 'value' => $address->getShqPbDutyAmount()
87
+ ));
88
+ }
89
+ }
90
+ }
app/code/community/Shipperhq/Pbint/Model/Resource/Mysql4/Setup.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Pitney Bowes International
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Pbint_Model_Resource_Mysql4_Setup extends Mage_Tax_Model_Mysql4_Setup {
32
+
33
+ }
app/code/community/Shipperhq/Pbint/Model/Variable.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Model_Variable extends Mage_Core_Model_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ parent::_construct();
36
+ $this->_init('shipperhq_pbint/variable');
37
+ }
38
+ }
39
+
40
+ ?>
app/code/community/Shipperhq/Pbint/README ADDED
@@ -0,0 +1,2 @@
 
 
1
+ Dependencies:
2
+ gnupg
app/code/community/Shipperhq/Pbint/changelog.txt ADDED
File without changes
app/code/community/Shipperhq/Pbint/controllers/Adminhtml/ShqpitneyController.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Pitney Bowes International
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Pbint_Adminhtml_ShqpitneyController extends Mage_Adminhtml_Controller_Action
32
+ {
33
+
34
+ public function uploadcatalogAction()
35
+ {
36
+ $pbExport = Mage::getModel('shipperhq_pbint/catalog_cron');
37
+ $result = $pbExport->uploadCatalog();
38
+ $pbExport->processStatusNotifications();
39
+ $session = Mage::getSingleton('Mage_Adminhtml_Model_Session');
40
+ $session->getMessages(true);
41
+ $success = 1;
42
+
43
+ if ($result === true) {
44
+ $message = Mage::helper('shipperhq_pbint')->__('Catalog synch was a success');
45
+ $session->addSuccess($message);
46
+ }
47
+ else {
48
+ $message = Mage::helper('shipperhq_pbint')->__(
49
+ 'Catalog synch with Pitney Bowes did not complete. ');
50
+ if(is_string($result)) {
51
+ $message .= $result;
52
+ }
53
+ else {
54
+ $message .= Mage::helper('shipperhq_pbint')->__('Please review your log files for error details');
55
+ }
56
+ $session->addError($message);
57
+ $success = 0;
58
+ }
59
+
60
+ $this->_initLayoutMessages('adminhtml/session');
61
+ $session_messages = $this->getLayout()->getMessagesBlock()->getGroupedHtml();
62
+
63
+ $result = array('result' => $success, 'message' => $message, 'session_messages' => $session_messages);
64
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
65
+ }
66
+ }
app/code/community/Shipperhq/Pbint/etc/config.xml ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shipperhq_Pbint>
5
+ <version>1.0.1</version>
6
+ </Shipperhq_Pbint>
7
+ </modules>
8
+ <admin>
9
+ <routers>
10
+ <adminhtml>
11
+ <args>
12
+ <modules>
13
+ <Shipperhq_Pbint after="Mage_Adminhtml">Shipperhq_Pbint_Adminhtml</Shipperhq_Pbint>
14
+ </modules>
15
+ </args>
16
+ </adminhtml>
17
+ </routers>
18
+ </admin>
19
+ <global>
20
+ <blocks>
21
+ <shipperhq_pbint>
22
+ <class>Shipperhq_Pbint_Block</class>
23
+ </shipperhq_pbint>
24
+ </blocks>
25
+ <helpers>
26
+ <shipperhq_pbint>
27
+ <class>Shipperhq_Pbint_Helper</class>
28
+ </shipperhq_pbint>
29
+ </helpers>
30
+ <models>
31
+ <shipperhq_pbint>
32
+ <class>Shipperhq_Pbint_Model</class>
33
+ <resourceModel>shipperhq_pbint_mysql4</resourceModel>
34
+ </shipperhq_pbint>
35
+ <shipperhq_pbint_mysql4>
36
+ <class>Shipperhq_Pbint_Model_Mysql4</class>
37
+ <entities>
38
+ <variable>
39
+ <table>shqpbint_variable</table>
40
+ </variable>
41
+ <ordernumber>
42
+ <table>shqpbint_ordernumber</table>
43
+ </ordernumber>
44
+ <inboundparcel>
45
+ <table>shqpbint_inbound_parcel</table>
46
+ </inboundparcel>
47
+ </entities>
48
+ </shipperhq_pbint_mysql4>
49
+ </models>
50
+ <resources>
51
+ <shqpbint_setup>
52
+ <setup>
53
+ <module>Shipperhq_Pbint</module>
54
+ <class>Shipperhq_Pbint_Model_Resource_Mysql4_Setup</class>
55
+ </setup>
56
+ <connection>
57
+ <use>core_setup</use>
58
+ </connection>
59
+ </shqpbint_setup>
60
+ <shipperhq_pbint_write>
61
+ <connection>
62
+ <use>core_write</use>
63
+ </connection>
64
+ </shipperhq_pbint_write>
65
+ <shipperhq_pbint_read>
66
+ <connection>
67
+ <use>core_read</use>
68
+ </connection>
69
+ </shipperhq_pbint_read>
70
+ </resources>
71
+ <events>
72
+ <core_block_abstract_to_html_after>
73
+ <observers>
74
+ <Shipperhq_Pbint_Model_OrderView>
75
+ <type>model</type>
76
+ <class>shipperhq_pbint/observer</class>
77
+ <method>modifyOrderView</method>
78
+ </Shipperhq_Pbint_Model_OrderView>
79
+ </observers>
80
+ </core_block_abstract_to_html_after>
81
+ <controller_action_postdispatch_checkout_cart_estimateUpdatePost>
82
+ <observers>
83
+ <Shipperhq_Pbint_Estimated_Shipping>
84
+ <type>model</type>
85
+ <class>shipperhq_pbint/observer</class>
86
+ <method>addDutiesOnEstimation</method>
87
+ </Shipperhq_Pbint_Estimated_Shipping>
88
+ </observers>
89
+ </controller_action_postdispatch_checkout_cart_estimateUpdatePost>
90
+ </events>
91
+ <sales>
92
+ <quote>
93
+ <totals>
94
+ <shq_pb_duty>
95
+ <class>Shipperhq_Pbint_Model_Quote_Duty</class>
96
+ <before>grand_total</before>
97
+ <after>tax</after>
98
+ </shq_pb_duty>
99
+ </totals>
100
+ </quote>
101
+ <order_invoice>
102
+ <totals>
103
+ <shq_pb_duty>
104
+ <class>Shipperhq_Pbint_Model_Invoice_Duty</class>
105
+ <before>grand_total</before>
106
+ <after>tax</after>
107
+ </shq_pb_duty>
108
+ </totals>
109
+ </order_invoice>
110
+ <order_creditmemo>
111
+ <totals>
112
+ <shq_pb_duty>
113
+ <class>Shipperhq_Pbint_Model_Creditmemo_Duty</class>
114
+ <before>grand_total</before>
115
+ <after>tax</after>
116
+ </shq_pb_duty>
117
+ </totals>
118
+ </order_creditmemo>
119
+ </sales>
120
+ <pdf>
121
+ <totals>
122
+ <shq_pb_duty translate="title">
123
+ <title>International Duty</title>
124
+ <source_field>shq_pb_duty</source_field>
125
+ <model>shipperhq_pbint/pdf_duty</model>
126
+ <font_size>7</font_size>
127
+ <display_zero>0</display_zero>
128
+ <sort_order>300</sort_order>
129
+ </shq_pb_duty>
130
+ </totals>
131
+ </pdf>
132
+ <template>
133
+ <email>
134
+ <wsa_email_shipment_template translate="label" module="sales">
135
+ <label>ShipperHQ Pitney Bowes Custom Shipment Email</label>
136
+ <file>sales/shipperhq_pitney_shipment_new.html</file>
137
+ <type>html</type>
138
+ </wsa_email_shipment_template>
139
+ </email>
140
+ </template>
141
+ <fieldsets>
142
+ <!-- copies data from quote address to order during the order placement -->
143
+ <sales_convert_quote_address>
144
+ <base_shq_pb_duty_amount>
145
+ <to_order>*</to_order>
146
+ </base_shq_pb_duty_amount>
147
+ <shq_pb_duty_amount>
148
+ <to_order>*</to_order>
149
+ </shq_pb_duty_amount>
150
+ </sales_convert_quote_address>
151
+ <!-- copies data from order to invoice/shipment/creditmemo during their creation -->
152
+ <sales_convert_order>
153
+ <base_shq_pb_duty_amount>
154
+ <to_invoice>*</to_invoice>
155
+ <to_shipment>*</to_shipment>
156
+ <to_cm>*</to_cm>
157
+ </base_shq_pb_duty_amount>
158
+ <shq_pb_duty_amount>
159
+ <to_invoice>*</to_invoice>
160
+ <to_shipment>*</to_shipment>
161
+ <to_cm>*</to_cm>
162
+ </shq_pb_duty_amount>
163
+ </sales_convert_order>
164
+ </fieldsets>
165
+ </global>
166
+ <default>
167
+ <shipperhqpitney>
168
+ <shqpbint>
169
+ <catalog_encryption_enabled>0</catalog_encryption_enabled>
170
+ <catalog_diff>1</catalog_diff>
171
+ <catalog_full>1</catalog_full>
172
+ <catalog_size>10000</catalog_size>
173
+ </shqpbint>
174
+ </shipperhqpitney>
175
+ </default>
176
+
177
+ <!-- Please modify this part for CRON JOB
178
+ For more information on Magento Cron Job, please visit the following url:
179
+ http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job#built-in_cron_jobs
180
+ -->
181
+ <crontab>
182
+ <jobs>
183
+ <shipperhq_pbint>
184
+ <schedule>
185
+ <cron_expr>30 * * * *</cron_expr>
186
+ </schedule>
187
+ <run>
188
+ <model>shipperhq_pbint/catalog_cron::catalogSync</model>
189
+ </run>
190
+ </shipperhq_pbint>
191
+ <pb_notifications>
192
+ <schedule>
193
+ <cron_expr>20 * * * *</cron_expr>
194
+ </schedule>
195
+ <run>
196
+ <model>shipperhq_pbint/catalog_cron::processStatusNotifications</model>
197
+ </run>
198
+ </pb_notifications>
199
+ </jobs>
200
+ </crontab>
201
+ <frontend>
202
+ <layout>
203
+ <updates>
204
+ <shipperhq_pbint module="Shipperhq_Pbint">
205
+ <file>shipperhq/pbint.xml</file>
206
+ </shipperhq_pbint>
207
+ </updates>
208
+ </layout>
209
+ </frontend>
210
+ <adminhtml>
211
+ <layout>
212
+ <updates>
213
+ <shipperhq_pbint module="Shipperhq_Pbint">
214
+ <file>shipperhq/pbint.xml</file>
215
+ </shipperhq_pbint>
216
+ </updates>
217
+ </layout>
218
+ <acl>
219
+ <resources>
220
+ <admin>
221
+ <children>
222
+ <system>
223
+ <children>
224
+ <config>
225
+ <children>
226
+ <shipperhqpitney>
227
+ <title>ShipperHQ Pitney Bowes International</title>
228
+ </shipperhqpitney>
229
+ </children>
230
+ </config>
231
+ </children>
232
+ </system>
233
+ </children>
234
+ </admin>
235
+ </resources>
236
+ </acl>
237
+ <translate>
238
+ <modules>
239
+ <translations>
240
+ <files>
241
+ <default>Shipperhq_Pbint.csv</default>
242
+ </files>
243
+ </translations>
244
+ </modules>
245
+ </translate>
246
+ </adminhtml>
247
+ </config>
248
+
app/code/community/Shipperhq/Pbint/etc/system.xml ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <shipperhq translate="label" module="shipperhq_pbint">
5
+ <label>ShipperHQ<!--<![CDATA[ <img src="http://www.webshopapps.com/images/logos/WSA_OfficialLogo_HorizontalLockup.png" alt='WebShopApps' height='22' /> ]]> -->
6
+ </label>
7
+ <sort_order>300</sort_order>
8
+ </shipperhq>
9
+ </tabs>
10
+ <sections>
11
+ <shipperhqpitney translate="label" module="shipperhq_pbint">
12
+ <label>ShipperHQ Pitney Bowes International</label>
13
+ <tab>shipperhq</tab>
14
+ <sort_order>40</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <shqpbint translate="label" module="shipperhq_pbint">
20
+ <label>ShipperHQ Pitney Bowes International</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>1</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <active translate="label">
28
+ <label>Enabled</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>1</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ </active>
36
+ <merchantcode translate="label">
37
+ <label>Merchant Code</label>
38
+ <frontend_type>text</frontend_type>
39
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
40
+ <sort_order>10</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ </merchantcode>
45
+ <ftpuser translate="label">
46
+ <label>SFTP username</label>
47
+ <frontend_type>text</frontend_type>
48
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
49
+ <sort_order>40</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ </ftpuser>
54
+ <ftppass translate="label">
55
+ <label>SFTP password</label>
56
+ <frontend_type>password</frontend_type>
57
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
58
+ <sort_order>50</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ </ftppass>
63
+ <ftphost translate="label">
64
+ <label>SFTP hostname</label>
65
+ <frontend_type>text</frontend_type>
66
+ <sort_order>60</sort_order>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>1</show_in_website>
69
+ <show_in_store>1</show_in_store>
70
+ </ftphost>
71
+ <ftpport translate="label">
72
+ <label>SFTP port</label>
73
+ <frontend_type>text</frontend_type>
74
+ <sort_order>70</sort_order>
75
+ <show_in_default>1</show_in_default>
76
+ <show_in_website>1</show_in_website>
77
+ <show_in_store>1</show_in_store>
78
+ </ftpport>
79
+ <ftpdir translate="label">
80
+ <label>SFTP catalog directory</label>
81
+ <frontend_type>text</frontend_type>
82
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
83
+ <sort_order>80</sort_order>
84
+ <show_in_default>1</show_in_default>
85
+ <show_in_website>1</show_in_website>
86
+ <show_in_store>1</show_in_store>
87
+ </ftpdir>
88
+ <catalog_diff translate="label">
89
+ <label>Catalog update period (hours, min 1 hour)</label>
90
+ <frontend_type>text</frontend_type>
91
+ <sort_order>90</sort_order>
92
+ <show_in_default>1</show_in_default>
93
+ <show_in_website>1</show_in_website>
94
+ <show_in_store>1</show_in_store>
95
+ </catalog_diff>
96
+ <catalog_full translate="label">
97
+ <label>Full catalog upload period (days)</label>
98
+ <frontend_type>text</frontend_type>
99
+ <sort_order>100</sort_order>
100
+ <show_in_default>1</show_in_default>
101
+ <show_in_website>1</show_in_website>
102
+ <show_in_store>1</show_in_store>
103
+ </catalog_full>
104
+ <catalog_size translate="label">
105
+ <label>Maximum Records Per File</label>
106
+ <frontend_type>text</frontend_type>
107
+ <validate>validate-number</validate>
108
+ <sort_order>105</sort_order>
109
+ <show_in_default>1</show_in_default>
110
+ <show_in_website>1</show_in_website>
111
+ <show_in_store>1</show_in_store>
112
+ </catalog_size>
113
+ <catalog_sender_id translate="label">
114
+ <label>Catalog Sender ID</label>
115
+ <frontend_type>text</frontend_type>
116
+ <sort_order>106</sort_order>
117
+ <show_in_default>1</show_in_default>
118
+ <show_in_website>1</show_in_website>
119
+ <show_in_store>1</show_in_store>
120
+ </catalog_sender_id>
121
+ <admin_email translate="label">
122
+ <label>Admin Email</label>
123
+ <frontend_type>text</frontend_type>
124
+ <validate>validate-email</validate>
125
+ <sort_order>110</sort_order>
126
+ <show_in_default>1</show_in_default>
127
+ <show_in_website>1</show_in_website>
128
+ <show_in_store>1</show_in_store>
129
+ </admin_email>
130
+ <catalog_encryption_enabled translate="label">
131
+ <label>Catalog Encryption Enabled</label>
132
+ <frontend_type>select</frontend_type>
133
+ <source_model>adminhtml/system_config_source_yesno</source_model>
134
+ <sort_order>115</sort_order>
135
+ <show_in_default>1</show_in_default>
136
+ <show_in_website>1</show_in_website>
137
+ <show_in_store>1</show_in_store>
138
+ </catalog_encryption_enabled>
139
+ <encryption_public_key translate="label">
140
+ <label>Catalog Encryption Public Key</label>
141
+ <frontend_type>textarea</frontend_type>
142
+ <sort_order>120</sort_order>
143
+ <show_in_default>1</show_in_default>
144
+ <show_in_website>1</show_in_website>
145
+ <show_in_store>1</show_in_store>
146
+ </encryption_public_key>
147
+ <retrieve_credentials translate="label">
148
+ <label>Upload to Pitney Bowes</label>
149
+ <frontend_type>select</frontend_type>
150
+ <frontend_model>shipperhq_pbint/adminhtml_system_upload</frontend_model>
151
+ <button_label>Upload Catalog Now</button_label>
152
+ <sort_order>150</sort_order>
153
+ <show_in_default>1</show_in_default>
154
+ <show_in_website>0</show_in_website>
155
+ <show_in_store>0</show_in_store>
156
+ </retrieve_credentials>
157
+ </fields>
158
+ </shqpbint>
159
+ </groups>
160
+ </shipperhqpitney>
161
+ </sections>
162
+ </config>
app/code/community/Shipperhq/Pbint/sql/shqpbint_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run("
8
+
9
+ DROP TABLE IF EXISTS {$this->getTable('shipperhq_pbint/variable')};
10
+ CREATE TABLE {$this->getTable('shipperhq_pbint/variable')} (
11
+ `variable_id` int(11) unsigned NOT NULL auto_increment,
12
+ `name` varchar(255) NOT NULL default '',
13
+ `value` varchar(255) NOT NULL default '',
14
+ PRIMARY KEY (`variable_id`)
15
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
16
+
17
+ DROP TABLE IF EXISTS {$this->getTable('shipperhq_pbint/ordernumber')};
18
+ CREATE TABLE {$this->getTable('shipperhq_pbint/ordernumber')} (
19
+ `ordernumber_id` int(11) unsigned NOT NULL auto_increment,
20
+ `cp_order_number` varchar(255) NOT NULL default '',
21
+ `mage_order_number` varchar(255) NOT NULL default '',
22
+ `confirmed` tinyint NOT NULL default 0,
23
+ `referenced` tinyint NOT NULL default 0,
24
+ `hub_id` varchar(50) null,
25
+ `hub_street1` varchar(50) null,
26
+ `hub_street2` varchar(50) null,
27
+ `hub_province_or_state` varchar(50) null,
28
+ `hub_postcode` varchar(50) null,
29
+ `hub_country` varchar(50) null,
30
+ PRIMARY KEY (`ordernumber_id`)
31
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
32
+
33
+ DROP TABLE IF EXISTS {$this->getTable('shipperhq_pbint/inboundparcel')};
34
+ CREATE TABLE {$this->getTable('shipperhq_pbint/inboundparcel')} (
35
+ `inbound_parcel_id` int(11) unsigned NOT NULL auto_increment,
36
+ `inbound_parcel` varchar(255) NOT NULL default '',
37
+ `mage_order_number` varchar(255) NOT NULL default '',
38
+ `pb_order_number` varchar(255) NOT NULL default '',
39
+ PRIMARY KEY (`inbound_parcel_id`)
40
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
41
+
42
+ ");
43
+
44
+ $eav = Mage::getResourceModel('catalog/setup', 'catalog_setup');//new Mage_Eav_Model_Entity_Setup('catalog_setup');
45
+ //$eav->removeAttribute('catalog_product','shipperhq_pbint_upload');
46
+ $eav->addAttribute('catalog_product', 'shipperhq_pbint_upload', array(
47
+ 'type' => 'int',
48
+ 'input' => 'text',
49
+ 'label' => 'Last PBGSP upload timestampt',
50
+ 'global' => 2,
51
+ 'user_defined' => 0,
52
+ 'required' => 0,
53
+ 'visible' => 1,
54
+ 'default' => 0
55
+
56
+ ));
57
+
58
+
59
+ $installer->addAttribute('quote_address', 'shq_pb_duty_amount', array('type'=>'decimal'));
60
+ $installer->addAttribute('quote_address', 'base_shq_pb_duty_amount', array('type'=>'decimal'));
61
+
62
+ $installer->addAttribute('order', 'shq_pb_duty_amount', array('type'=>'decimal'));
63
+ $installer->addAttribute('order', 'base_shq_pb_duty_amount', array('type'=>'decimal'));
64
+
65
+ $installer->addAttribute('invoice', 'shq_pb_duty_amount', array('type'=>'decimal'));
66
+ $installer->addAttribute('invoice', 'base_shq_pb_duty_amount', array('type'=>'decimal'));
67
+
68
+ $installer->addAttribute('creditmemo', 'shq_pb_duty_amount', array('type'=>'decimal'));
69
+ $installer->addAttribute('creditmemo', 'base_shq_pb_duty_amount', array('type'=>'decimal'));
70
+
71
+ $installer->endSetup();
72
+ ?>
app/code/community/Shipperhq/Pbint/sql/shqpbint_setup/mysql4-install-1.0.1.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run("
8
+
9
+ DROP TABLE IF EXISTS {$this->getTable('shipperhq_pbint/variable')};
10
+ CREATE TABLE {$this->getTable('shipperhq_pbint/variable')} (
11
+ `variable_id` int(11) unsigned NOT NULL auto_increment,
12
+ `name` varchar(255) NOT NULL default '',
13
+ `value` varchar(255) NOT NULL default '',
14
+ PRIMARY KEY (`variable_id`)
15
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
16
+
17
+ DROP TABLE IF EXISTS {$this->getTable('shipperhq_pbint/ordernumber')};
18
+ CREATE TABLE {$this->getTable('shipperhq_pbint/ordernumber')} (
19
+ `ordernumber_id` int(11) unsigned NOT NULL auto_increment,
20
+ `cp_order_number` varchar(255) NOT NULL default '',
21
+ `mage_order_number` varchar(255) NOT NULL default '',
22
+ `confirmed` tinyint NOT NULL default 0,
23
+ `referenced` tinyint NOT NULL default 0,
24
+ `hub_id` varchar(50) null,
25
+ `hub_street1` varchar(50) null,
26
+ `hub_street2` varchar(50) null,
27
+ `hub_city` varchar(50) null,
28
+ `hub_province_or_state` varchar(50) null,
29
+ `hub_postcode` varchar(50) null,
30
+ `hub_country` varchar(50) null,
31
+ PRIMARY KEY (`ordernumber_id`)
32
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
33
+
34
+ DROP TABLE IF EXISTS {$this->getTable('shipperhq_pbint/inboundparcel')};
35
+ CREATE TABLE {$this->getTable('shipperhq_pbint/inboundparcel')} (
36
+ `inbound_parcel_id` int(11) unsigned NOT NULL auto_increment,
37
+ `inbound_parcel` varchar(255) NOT NULL default '',
38
+ `mage_order_number` varchar(255) NOT NULL default '',
39
+ `pb_order_number` varchar(255) NOT NULL default '',
40
+ PRIMARY KEY (`inbound_parcel_id`)
41
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
42
+
43
+ ");
44
+
45
+ $eav = Mage::getResourceModel('catalog/setup', 'catalog_setup');//new Mage_Eav_Model_Entity_Setup('catalog_setup');
46
+ //$eav->removeAttribute('catalog_product','shipperhq_pbint_upload');
47
+ $eav->addAttribute('catalog_product', 'shipperhq_pbint_upload', array(
48
+ 'type' => 'int',
49
+ 'input' => 'text',
50
+ 'label' => 'Last PBGSP upload timestampt',
51
+ 'global' => 2,
52
+ 'user_defined' => 0,
53
+ 'required' => 0,
54
+ 'visible' => 1,
55
+ 'default' => 0
56
+
57
+ ));
58
+
59
+
60
+ $installer->addAttribute('quote_address', 'shq_pb_duty_amount', array('type'=>'decimal'));
61
+ $installer->addAttribute('quote_address', 'base_shq_pb_duty_amount', array('type'=>'decimal'));
62
+
63
+ $installer->addAttribute('order', 'shq_pb_duty_amount', array('type'=>'decimal'));
64
+ $installer->addAttribute('order', 'base_shq_pb_duty_amount', array('type'=>'decimal'));
65
+
66
+ $installer->addAttribute('invoice', 'shq_pb_duty_amount', array('type'=>'decimal'));
67
+ $installer->addAttribute('invoice', 'base_shq_pb_duty_amount', array('type'=>'decimal'));
68
+
69
+ $installer->addAttribute('creditmemo', 'shq_pb_duty_amount', array('type'=>'decimal'));
70
+ $installer->addAttribute('creditmemo', 'base_shq_pb_duty_amount', array('type'=>'decimal'));
71
+
72
+ $installer->endSetup();
73
+ ?>
app/code/community/Shipperhq/Pbint/sql/shqpbint_setup/mysql4-upgrade-1.0.0-1.0.1.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ $pbOrderTable = $installer->getTable('shipperhq_pbint/ordernumber');
8
+
9
+ if(!$installer->getConnection()->tableColumnExists($pbOrderTable, 'hub_city')){
10
+ $text = Mage::helper('wsalogger')->getNewVersion() > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : 'text';
11
+
12
+ $hubCity = array(
13
+ 'type' => $text,
14
+ 'length' => 50,
15
+ 'comment' => 'Hub city',
16
+ 'nullable' => 'true',
17
+ );
18
+ $installer->getConnection()
19
+ ->addColumn(
20
+ $pbOrderTable,
21
+ 'hub_city',
22
+ $hubCity
23
+ );
24
+ }
25
+
26
+ $installer->endSetup();
27
+
28
+
29
+
app/code/community/Shipperhq/Shipper/Block/Adminhtml/Carrier/About.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Shipping
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ class Shipperhq_Shipper_Block_Adminhtml_Carrier_About extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
32
+ {
33
+ /**
34
+ * Return header comment part of html for fieldset
35
+ *
36
+ * @param Varien_Data_Form_Element_Abstract $element
37
+ * @return string
38
+ */
39
+ protected function _getHeaderCommentHtml($element)
40
+ {
41
+ $beforeDiv = '<div style="padding:10px;background-color:#fff;border:1px solid #ddd;margin-bottom:7px;">';
42
+ $afterDiv = '</div>';
43
+ $synch = $this->helper('index')->__('Click here to <a href="%s">Synchronize</a> with ShipperHQ.', $this->getUrl('adminhtml/shqsynchronize'));
44
+ $element->getComment()
45
+ ? $comment = $element->getComment()
46
+ : $comment = '';
47
+ $html =$beforeDiv. '<table>
48
+ <tr>
49
+ <td width="100px;"><img style="height: 36px; padding: 0px 0px;" class="logo" src="'.$this->getSkinUrl('shipperhq/images/shq-logo.png') .'" alt="ShipperHQ"/></td>
50
+ <td width="10"></td>
51
+ <td style="vertical-align:bottom">
52
+ <h4>ShipperHQ installed version '. $this->getModuleVersion() .'</h4>
53
+ </td>
54
+ </tr>
55
+ <tr>
56
+ <td colspan="3">
57
+ <p>'.$comment.'</p>
58
+ </td>
59
+ </tr>
60
+ <tr>
61
+ <td colspan="3">
62
+ <p>'. $synch .'</p>
63
+ </td>
64
+ </tr>
65
+ </table>' .$afterDiv;
66
+ return $html;
67
+ }
68
+
69
+ protected function getModuleVersion() {
70
+ return (string) Mage::getConfig()->getNode('modules/Shipperhq_Shipper/extension_version');
71
+ }
72
+ }
app/code/community/Shipperhq/Shipper/Block/Adminhtml/Carrier/Heading.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Shipping
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+
32
+ class Shipperhq_Shipper_Block_Adminhtml_Carrier_Heading
33
+ extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface
34
+ {
35
+ /**
36
+ * Render element html
37
+ *
38
+ * @param Varien_Data_Form_Element_Abstract $element
39
+ * @return string
40
+ */
41
+ public function render(Varien_Data_Form_Element_Abstract $element)
42
+ {
43
+ $useContainerId = $element->getData('use_container_id');
44
+ return sprintf('<tr class="system-fieldset-sub-head" id="row_%s"><td colspan="5"><h4>%s</h4></td></tr>',
45
+ $element->getHtmlId(), $element->getLabel()
46
+ );
47
+ }
48
+ }
app/code/community/Shipperhq/Shipper/Block/Adminhtml/Carrier/Refreshcarriers.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Block_Adminhtml_Carrier_Refreshcarriers
32
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
33
+ {
34
+
35
+ protected function _prepareLayout()
36
+ {
37
+ parent::_prepareLayout();
38
+ if (!$this->getTemplate()) {
39
+ $this->setTemplate('shipperhq/shipper/system/carrier/refreshcarriers.phtml');
40
+ }
41
+ return $this;
42
+ }
43
+
44
+ /**
45
+ * Unset some non-related element parameters
46
+ *
47
+ * @param Varien_Data_Form_Element_Abstract $element
48
+ * @return string
49
+ */
50
+ public function render(Varien_Data_Form_Element_Abstract $element)
51
+ {
52
+ $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
53
+ return parent::render($element);
54
+ }
55
+
56
+ /**
57
+ * Get the button and scripts contents
58
+ *
59
+ * @param Varien_Data_Form_Element_Abstract $element
60
+ * @return string
61
+ */
62
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
63
+ {
64
+ $originalData = $element->getOriginalData();
65
+ $this->addData(array(
66
+ 'button_label' => Mage::helper('customer')->__($originalData['button_label']),
67
+ 'html_id' => $element->getHtmlId(),
68
+ 'ajax_url' => Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/Shqajax/refreshcarriers')
69
+ ));
70
+
71
+ return $this->_toHtml();
72
+ }
73
+
74
+ }
app/code/community/Shipperhq/Shipper/Block/Adminhtml/Catalog/Product/Edit/Tab/Dimensional.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Adminhtml
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Recurring profile attribute edit renderer
29
+ */
30
+ class Shipperhq_Shipper_Block_Adminhtml_Catalog_Product_Edit_Tab_Dimensional
31
+ extends Mage_Adminhtml_Block_Catalog_Form_Renderer_Fieldset_Element
32
+ {
33
+ /**
34
+ * Element output getter
35
+ *
36
+ * @return string
37
+ */
38
+ public function getElementHtml()
39
+ {
40
+ $result = new StdClass;
41
+ $result->output = '';
42
+ $html = parent::getElementHtml();
43
+ Mage::dispatchEvent('catalog_product_edit_form_render_packingboxes', array(
44
+ 'result' => $result,
45
+ 'product_element' => $this->_element,
46
+ 'product' => Mage::registry('current_product'),
47
+ ));
48
+ return $html .$result->output;
49
+ }
50
+ }
app/code/community/Shipperhq/Shipper/Block/Adminhtml/Synchronize.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Block_Adminhtml_Synchronize extends Mage_Adminhtml_Block_Widget_Grid_Container
32
+ {
33
+ public function __construct()
34
+ {
35
+ $this->_controller = 'adminhtml_synchronize';
36
+ $this->_blockGroup = 'shipperhq_shipper';
37
+ $this->_headerText = Mage::helper('shipperhq_shipper')->__('Synchronize with ShipperHQ');
38
+
39
+ parent::__construct();
40
+ $this->_removeButton('add');
41
+ $this->_addButton('refresh', array(
42
+ 'label' => 'Refresh Comparison',
43
+ 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/refresh') .'\')',
44
+ 'class' => 'add',
45
+ ));
46
+
47
+ // 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/synchronize') .'\')',
48
+ $this->_addButton('synchronize', array(
49
+ 'label' => 'Synchronize with ShipperHQ',
50
+ 'onclick' => 'confirmSetLocation(\''
51
+ . Mage::helper('shipperhq_shipper')->__('Are you sure?').'\', \''.$this->getUrl('*/*/synchronize').'\')',
52
+ 'class' => 'add',
53
+ ));
54
+
55
+
56
+ }
57
+ }
app/code/community/Shipperhq/Shipper/Block/Adminhtml/Synchronize/Grid.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+
32
+ class Shipperhq_Shipper_Block_Adminhtml_Synchronize_Grid extends Mage_Adminhtml_Block_Widget_Grid
33
+ {
34
+ public function _construct()
35
+ {
36
+ parent::_construct();
37
+ $this->setId('synchronizeGrid');
38
+ $this->setDefaultDir('ASC');
39
+ $this->setSaveParametersInSession(true);
40
+ $this->_filterVisibility = false;
41
+ $this->_pagerVisibility = false;
42
+ }
43
+
44
+ protected function _prepareCollection()
45
+ {
46
+ $collection = Mage::getModel('shipperhq_shipper/attributeupdate')->getCollection();
47
+ $this->setCollection($collection);
48
+ return parent::_prepareCollection();
49
+ }
50
+
51
+ protected function _prepareColumns()
52
+ {
53
+ $this->addColumn('attribute_code', array(
54
+ 'header' => Mage::helper('shipperhq_shipper')->__('Attribute'),
55
+ 'align' =>'left',
56
+ 'width' => '400px',
57
+ 'index' => 'attribute_code',
58
+ ));
59
+
60
+ $this->addColumn('value', array(
61
+ 'header' => Mage::helper('shipperhq_shipper')->__('Value'),
62
+ 'align' =>'left',
63
+ 'index' => 'value',
64
+ ));
65
+
66
+ $this->addColumn('status', array(
67
+ 'header' => Mage::helper('shipperhq_shipper')->__('Status'),
68
+ 'align' =>'left',
69
+ 'index' => 'status',
70
+ 'width' => '150',
71
+ 'frame_callback' => array($this, 'decorateStatus')
72
+
73
+ ));
74
+ $this->setPagerVisibility(true);
75
+
76
+ return parent::_prepareColumns();
77
+ }
78
+
79
+
80
+ /**
81
+ * Decorate status column values
82
+ *
83
+ * @return string
84
+ */
85
+ public function decorateStatus($value, $row, $column, $isExport)
86
+ {
87
+ $class = '';
88
+ if ($value == Shipperhq_Shipper_Model_Synchronize::REMOVE_ATTRIBUTE_OPTION) {
89
+ $cell = '<span class="grid-severity-critical"><span>'.$this->__($value).'</span></span>';
90
+ } else {
91
+ $cell = $this->__($value);
92
+
93
+ }
94
+ return $cell;
95
+ }
96
+ }
app/code/community/Shipperhq/Shipper/Block/Adminhtml/Synchronize/Notify.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Adminhtml
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class Shipperhq_Shipper_Block_Adminhtml_Synchronize_Notify extends Mage_Adminhtml_Block_Template
28
+ {
29
+ // Cache kay for saving verification result
30
+ const SYNCH_STATUS_RESULT_CACHE_KEY = 'shipperhq_shipper_synch_status';
31
+
32
+ /**
33
+ * File path for verification
34
+ * @var string
35
+ */
36
+ private $_filePath = 'app/etc/local.xml';
37
+
38
+ /**
39
+ * Time out for HTTP verification request
40
+ * @var int
41
+ */
42
+ private $_verificationTimeOut = 2;
43
+
44
+
45
+ public function getSynchUrl()
46
+ {
47
+ return $this->getUrl('adminhtml/shqsynchronize');
48
+ }
49
+ /**
50
+ * Check verification result and return true if system must to show notification message
51
+ *
52
+ * @return bool
53
+ */
54
+ protected function _canShowNotification()
55
+ {
56
+ if(Mage::getSingleton('adminhtml/session')->getAlreadySynched()) {
57
+ return false;
58
+ }
59
+
60
+ if ($this->_isSynchRequired()) {
61
+ return true;
62
+ }
63
+
64
+ Mage::getSingleton('adminhtml/session')->setAlreadySynched(true);
65
+ return false;
66
+ }
67
+
68
+ /**
69
+ * Check synchronization status
70
+ *
71
+ * @return bool
72
+ */
73
+ protected function _isSynchRequired()
74
+ {
75
+ $synchStatus = Mage::getModel('shipperhq_shipper/synchronize')->checkSynchStatus();
76
+ if($synchStatus != false) {
77
+ if($synchStatus != "1") {
78
+ return true;
79
+ }
80
+ }
81
+ return false;
82
+ }
83
+
84
+ /**
85
+ * Prepare html output
86
+ *
87
+ * @return string
88
+ */
89
+ protected function _toHtml()
90
+ {
91
+ if (!$this->_canShowNotification()) {
92
+ return '';
93
+ }
94
+ return parent::_toHtml();
95
+ }
96
+
97
+ }
app/code/community/Shipperhq/Shipper/Block/Adminhtml/System/Config/Fieldset/Shipper/Hint.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+
32
+ /**
33
+ * Renderer for ShipperHQ banner in System Configuration
34
+ */
35
+ class Shipperhq_Shipper_Block_Adminhtml_System_Config_Fieldset_Shipper_Hint
36
+ extends Mage_Backend_Block_Abstract
37
+ implements Varien_Data_Form_Element_Renderer_Interface
38
+ {
39
+ protected $_template = 'system/config/fieldset/hint.phtml';
40
+
41
+ /**
42
+ * Render fieldset html
43
+ *
44
+ * @param Varien_Data_Form_Element_Abstract $element
45
+ * @return string
46
+ */
47
+ public function render(Varien_Data_Form_Element_Abstract $element)
48
+ {
49
+ return $this->toHtml();
50
+ }
51
+ }
app/code/community/Shipperhq/Shipper/Helper/Data.php ADDED
@@ -0,0 +1,1026 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Shipping data helper
33
+ */
34
+ class Shipperhq_Shipper_Helper_Data extends Mage_Core_Helper_Abstract
35
+ {
36
+ protected static $_debug;
37
+ protected static $_showTransId;
38
+ protected static $_dateFormat;
39
+ protected static $_zendDateFormat;
40
+ protected static $_datepickerFormat;
41
+ protected static $_shortDateFormat;
42
+ protected static $_wsTimeout;
43
+ protected $_prodAttributes;
44
+ protected $_baseCurrencyRate;
45
+
46
+ /**
47
+ * @var Shipperhq_Shipper_Model_Storage_Manager
48
+ */
49
+ protected $_storageManager;
50
+
51
+ /**
52
+ * @var Mage_Sales_Model_Quote
53
+ */
54
+ protected $_quote;
55
+
56
+ public $magentoCarrierCodes =
57
+ array( 'ups' => 'ups',
58
+ 'fedEx' => 'fedex',
59
+ 'usps' => 'usps',
60
+ 'dhl' => 'dhl',
61
+ 'dhlint' => 'dhlint'
62
+ );
63
+
64
+ CONST CALENDAR_DATE_OPTION = 'calendar';
65
+ CONST DELIVERY_DATE_OPTION = 'delivery_date';
66
+ CONST TIME_IN_TRANSIT = 'time_in_transit';
67
+ CONST SHIPPERHQ_SHIPPER_CARRIERGROUP_DESC_PATH = 'carriers/shipper/carriergroup_describer';
68
+
69
+ /**
70
+ * Check is module exists and enabled in global config.
71
+ *
72
+ * @param $moduleName
73
+ */
74
+ public function isModuleEnabled($moduleName = null,$enabledLocation=null)
75
+ {
76
+ if ($moduleName === null) {
77
+ $moduleName = $this->_getModuleName();
78
+ }
79
+
80
+ if (!Mage::getConfig()->getNode('modules/' . $moduleName)) {
81
+ return false;
82
+ }
83
+
84
+ $isActive = Mage::getConfig()->getNode('modules/' . $moduleName . '/active');
85
+ if (!$isActive || !in_array((string)$isActive, array('true', '1'))) {
86
+ return false;
87
+ }
88
+
89
+ if ($enabledLocation === null) {
90
+ return true;
91
+ }
92
+
93
+ if (!Mage::getStoreConfig($enabledLocation)) {
94
+ return false;
95
+ }
96
+
97
+ return true;
98
+ }
99
+
100
+ /**
101
+ * Retrieve debug configuration
102
+ * @return boolean
103
+ */
104
+ public function isDebug()
105
+ {
106
+ if (self::$_debug == NULL) {
107
+ self::$_debug = Mage::helper('wsalogger')->isDebug('Shipperhq_Shipper');
108
+ }
109
+ return self::$_debug;
110
+ }
111
+
112
+
113
+ /**
114
+ * Retrieve debug configuration
115
+ * @return boolean
116
+ */
117
+ public function isTransactionIdEnabled()
118
+ {
119
+ if (self::$_showTransId == NULL) {
120
+ self::$_showTransId = Mage::getStoreConfigFlag('carriers/shipper/display_transaction');
121
+ }
122
+ return self::$_showTransId;
123
+
124
+ }
125
+
126
+ public function getTransactionId()
127
+ {
128
+ $id = Mage::registry('shipperhq_transaction');
129
+ return $id;
130
+ }
131
+
132
+ /**
133
+ * Returns an instance of storage manager
134
+ *
135
+ * @return Shipperhq_Shipper_Model_Storage_Manager
136
+ */
137
+ public function storageManager()
138
+ {
139
+ if ($this->_storageManager === null) {
140
+ $this->_storageManager = Mage::getModel('shipperhq_shipper/storage_manager');
141
+ }
142
+
143
+ return $this->_storageManager;
144
+ }
145
+
146
+ /**
147
+ * Returns a storage for a quote
148
+ *
149
+ * @param Mage_Sales_Model_Quote|null $quote
150
+ * @return Shipperhq_Shipper_Model_Storage|bool
151
+ */
152
+ public function getQuoteStorage($quote = null)
153
+ {
154
+ if ($quote === null) {
155
+ $quote = $this->getQuote();
156
+ }
157
+
158
+ return $this->storageManager()->findByQuote($quote);
159
+ }
160
+
161
+ public function chooseCarrierAndProcess($carrierRate, $carrierGroupId = null, $carrierGroupDetail = null, $isSplit = false)
162
+ {
163
+ $carrierCode = $carrierRate->carrierCode;
164
+ $sort = isset($carrierRate->sortOrder) ? $carrierRate->sortOrder : false;
165
+ $this->_dynamicCarrierConfig($carrierCode, $carrierRate->carrierType, $carrierRate->carrierTitle, $sort);
166
+
167
+ $isCalendar = false;
168
+ $calendarDetails = (array)$carrierRate->calendarDetails;
169
+ if(isset($carrierRate->dateOption) && $carrierRate->dateOption == self::CALENDAR_DATE_OPTION) {
170
+ $isCalendar = true;
171
+ }
172
+ elseif (!empty($calendarDetails) && !isset($carrierRate->dateOption)) {
173
+ //backwards compatibility
174
+ $isCalendar = true;
175
+ }
176
+
177
+ $this->populateCarrierLevelDetails((array)$carrierRate, $carrierGroupDetail);
178
+ if ($this->isModuleEnabled('Shipperhq_Pickup') && Mage::helper('shipperhq_pickup')->isPickupEnabledCarrier($carrierRate->carrierType)) {
179
+ if (!Mage::registry('pickup_carrier')) {
180
+ $model = Mage::getModel('shipperhq_pickup/carrier_storepickup');
181
+ Mage::register('pickup_carrier', $model);
182
+ }
183
+ return Mage::registry('pickup_carrier')->extractShipperhqRates($carrierRate, $carrierGroupId, $carrierGroupDetail, $isSplit);
184
+ }
185
+ else if ($this->isModuleEnabled('Shipperhq_Calendar') && $isCalendar) {
186
+ if (!Mage::registry('calendar_carrier')) {
187
+ $model = Mage::getModel('shipperhq_calendar/carrier_calendar');
188
+ Mage::register('calendar_carrier', $model);
189
+ }
190
+ return Mage::registry('calendar_carrier')->extractShipperhqRates($carrierRate, $carrierGroupId, $carrierGroupDetail, $isSplit);
191
+ }
192
+ //Always process rates with standard if not already done
193
+ if (!Mage::registry('shipper_carrier')) {
194
+ $model = Mage::getModel('shipperhq_shipper/carrier_shipper');
195
+ Mage::register('shipper_carrier', $model);
196
+ }
197
+ return Mage::registry('shipper_carrier')->extractShipperhqRates($carrierRate, $carrierGroupId, $carrierGroupDetail, $isSplit);
198
+ }
199
+
200
+ public function populateCarrierLevelDetails($carrierRate, &$carrierGroupDetail)
201
+ {
202
+
203
+ $carrierGroupDetail['carrierType'] = $carrierRate['carrierType'];
204
+ $carrierGroupDetail['carrierTitle'] = $carrierRate['carrierTitle'];
205
+ $carrierGroupDetail['carrier_code'] = $carrierRate['carrierCode'];
206
+ $carrierGroupDetail['carrierName'] = $carrierRate['carrierName'];
207
+ $shippingAddress = $this->getQuote()->getShippingAddress();
208
+
209
+ //store packages
210
+ if(array_key_exists('shipments', $carrierRate) && $carrierRate['shipments'] != null) {
211
+ if(!$this->getQuote()->getShippingAddress()->getAddressId()) {
212
+ return;
213
+ }
214
+ $cgId = array_key_exists('carrierGroupId', $carrierGroupDetail) ? $carrierGroupDetail['carrierGroupId'] : null;
215
+ $this->cleanUpPackages($shippingAddress->getAddressId(),$cgId, $carrierRate['carrierCode']);
216
+ $mapping = $this->getPackagesMapping();
217
+ $standardData = array('address_id' => $shippingAddress->getAddressId(),
218
+ 'carrier_group_id' => $cgId,
219
+ 'carrier_code' => $carrierRate['carrierCode']);
220
+ foreach($carrierRate['shipments'] as $shipment) {
221
+ $data = array_merge($standardData, Mage::helper('shipperhq_shipper/mapper')->map($mapping,(array)$shipment));
222
+ $package = Mage::getModel('shipperhq_shipper/quote_packages');
223
+ $package->setData($data);
224
+ $package->save();
225
+ }
226
+ }
227
+
228
+ if(array_key_exists('rates', $carrierRate) && $carrierRate['rates'] != null) {
229
+ foreach($carrierRate['rates'] as $rate) {
230
+ $cgId = array_key_exists('carrierGroupId', $carrierGroupDetail) ? $carrierGroupDetail['carrierGroupId'] : null;
231
+ $this->cleanUpPackages($shippingAddress->getAddressId(),$cgId, $carrierRate['carrierCode'].'_'.$rate->code);
232
+ $mapping = $this->getPackagesMapping();
233
+ $standardData = array('address_id' => $shippingAddress->getAddressId(),
234
+ 'carrier_group_id' => $cgId,
235
+ 'carrier_code' => $carrierRate['carrierCode'].'_'.$rate->code);
236
+ if(!isset($rate->shipments)) {
237
+ continue;
238
+ }
239
+ foreach($rate->shipments as $shipment) {
240
+ $data = array_merge($standardData, Mage::helper('shipperhq_shipper/mapper')->map($mapping,(array)$shipment));
241
+ $package = Mage::getModel('shipperhq_shipper/quote_packages');
242
+ $package->setData($data);
243
+ $package->save();
244
+ }
245
+ }
246
+ }
247
+ }
248
+
249
+ public function isPackageBreakdownDisplayEnabled()
250
+ {
251
+ return Mage::helper('wsalogger')->isDebugError();
252
+ }
253
+
254
+ protected function cleanUpPackages($addressId, $carrierGroupId, $carrier_code)
255
+ {
256
+ try{
257
+ $packages = Mage::getModel('shipperhq_shipper/quote_packages')->loadByCarrier($addressId, $carrierGroupId, $carrier_code);
258
+ foreach($packages as $old)
259
+ {
260
+ $old->delete();
261
+ }
262
+ }
263
+ catch (Exception $e) {
264
+ $result = false;
265
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
266
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Shipper',
267
+ 'Unable to remove existing packages', $e->getMessage());
268
+ }
269
+ }
270
+
271
+ }
272
+ protected function getPackagesMapping()
273
+ {
274
+ return array(
275
+ 'package_name' => 'name',
276
+ 'length' => 'length',
277
+ 'width' => 'width',
278
+ 'height' => 'height',
279
+ 'weight' => 'weight',
280
+ 'surcharge_price' => 'surchargePrice',
281
+ 'declared_value' => 'declaredValue',
282
+ 'items' => 'boxedItems'
283
+ );
284
+ }
285
+
286
+ public function getPackageBreakdown($carrierGroupId, $carrier_code)
287
+ {
288
+ if($this->isPackageBreakdownDisplayEnabled()) {
289
+ $packages = Mage::getModel('shipperhq_shipper/quote_packages')->loadByCarrier(
290
+ $this->getQuote()->getShippingAddress()->getAddressId(),$carrierGroupId, $carrier_code);
291
+ return $this->getPackageBreakdownText($packages);
292
+ }
293
+
294
+ }
295
+
296
+ public function getPackageBreakdownText($packages) {
297
+ $boxText = '';
298
+ $count = 1;
299
+ foreach ($packages as $key=>$box)
300
+ {
301
+ $boxText .= Mage::helper('shipperhq_shipper')->__('Package').' #'.($count++);
302
+
303
+ if ($box!=null) {
304
+ $boxText .= ' Box name: ' .$box['package_name'];
305
+ $boxText .= ' : ' . $box['length'];
306
+ $boxText .= 'x' . $box['width'] ;
307
+ $boxText .= 'x'. $box['height'] ;
308
+ $boxText .= ': W='.$box['weight'] . ':' ;
309
+ $boxText .= ' Value='.$box['declaredValue']. ':';
310
+ $boxText .= $this->getProductBreakdownText($box);
311
+ }
312
+ $boxText .= '</br>';
313
+ }
314
+ $boxText .= 'Transaction ID: ' .$this->getTransactionId();
315
+ return $boxText;
316
+ }
317
+
318
+ public function getProductBreakdownText($box) {
319
+ $productText = '';
320
+ $weightUnit = $this->getGlobalSetting('weightUnit');
321
+ if(!$weightUnit) {
322
+ $weightUnit = '';
323
+ }
324
+ if (array_key_exists('items',$box) || (is_object($box) && !is_null($box->getItems()))) {
325
+ if (is_array($box['items'])) {
326
+ foreach ($box['items'] as $item) {
327
+ $productText .= ' SKU=' .$item['qty_packed'] .' * '.$item['sku'] .' ' .$item['weight_packed'] .$weightUnit .'; ';
328
+ }
329
+ } else {
330
+ $productText = $box['items'];
331
+ }
332
+ }
333
+ return $productText;
334
+ }
335
+
336
+
337
+ public function populateRateLevelDetails($rate, &$carrierGroupDetail, $currencyConversionRate)
338
+ {
339
+ $carrierGroupDetail['methodTitle'] = $rate['name'];
340
+ $carrierGroupDetail['price'] = (float)$rate['totalCharges']*$currencyConversionRate;
341
+ $carrierGroupDetail['cost'] = (float)$rate['shippingPrice']*$currencyConversionRate;
342
+ $carrierGroupDetail['code'] = $rate['code'];
343
+
344
+
345
+ }
346
+
347
+ public function getBaseCurrencyRate($code)
348
+ {
349
+ $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
350
+ if (!in_array($code, $allowedCurrencies)) {
351
+ return false;
352
+ }
353
+ $baseCurrencyCode = Mage::app()->getStore()->getBaseCurrency()->getCode();
354
+ if (!$this->_baseCurrencyRate) {
355
+ $this->_baseCurrencyRate = Mage::getModel('directory/currency')
356
+ ->load($code)
357
+ ->getAnyRate($baseCurrencyCode);
358
+ }
359
+
360
+ return $this->_baseCurrencyRate > 0 ? $this->_baseCurrencyRate : false;
361
+
362
+ }
363
+ public function setStandardShipperResponseType()
364
+ {
365
+ $shipping = $this->getQuote()->getShippingAddress();
366
+ if($shipping->getSplitRates()) {
367
+ $shipping->setSplitRates(0);
368
+ }
369
+ }
370
+
371
+ public function isCheckout()
372
+ {
373
+
374
+ $shipping = $this->getQuote()->getShippingAddress();
375
+ $isCheckout = $shipping->getIsCheckout();
376
+ if($this->getQuote()->getIsMultiShipping()) {
377
+ return true;
378
+ }
379
+ return $isCheckout;
380
+ }
381
+
382
+ public function isMultiAddressCheckout()
383
+ {
384
+ return $this->getQuote()->getIsMultiShipping();
385
+ }
386
+
387
+ /**
388
+ * Determine template to use based on cart attributes
389
+ *
390
+ * @return boolean
391
+ */
392
+ public function getAvailableTemplate()
393
+ {
394
+
395
+ $splitRates = $this->getQuote()->getShippingAddress()->getSplitRates();
396
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Splitrates')
397
+ && $splitRates == 1) {
398
+ return 'shipperhq/checkout/onepage/shipping_method/available.phtml';
399
+ }
400
+ elseif($this->isModuleEnabled('Shipperhq_Pickup')) {
401
+ return 'shipperhq/checkout/onepage/shipping_method/available.phtml';
402
+ }
403
+ return 'checkout/onepage/shipping_method/available.phtml';
404
+ }
405
+
406
+ /**
407
+ * Set template for multiaddress checkout if enabled
408
+ *
409
+ * @return string
410
+ */
411
+ public function getMultiAddressTemplate()
412
+ {
413
+ if(Mage::getStoreConfig('carriers/shipper/active')) {
414
+ return 'shipperhq/checkout/multishipping/shipping.phtml';
415
+ }
416
+ return 'checkout/multishipping/shipping.phtml';
417
+ }
418
+
419
+ public function getMultiAddressOverviewTemplate()
420
+ {
421
+ if(Mage::getStoreConfig('carriers/shipper/active')) {
422
+ return 'shipperhq/checkout/multishipping/overview.phtml';
423
+ }
424
+ return "checkout/multishipping/overview.phtml";
425
+ }
426
+ /*
427
+ * Set template for onestepcheckout if enabled
428
+ *
429
+ * @return string
430
+ */
431
+ public function getOnestepcheckoutShippingTemplate()
432
+ {
433
+ if(Mage::getStoreConfig('carriers/shipper/active')) {
434
+ if(Mage::getStoreConfig('onestepcheckout/general/condense_shipping_methods')) {
435
+ return 'shipperhq/checkout/onestepcheckout/shipping_method_osc_shq.phtml';
436
+ }
437
+ else {
438
+ return 'shipperhq/checkout/onestepcheckout/shipping_method_osc_shq_radio.phtml';
439
+ }
440
+ }
441
+ return 'onestepcheckout/shipping_method.phtml';
442
+ }
443
+
444
+ /**
445
+ * Retrieve url for getting allowed methods
446
+ * @return string
447
+ */
448
+ public function getAllowedMethodGatewayUrl()
449
+ {
450
+ return $this->_getGatewayUrl().'allowed_methods';
451
+ }
452
+
453
+ /**
454
+ * Retrieve url for getting shipping rates
455
+ * @return string
456
+ */
457
+ public function getRateGatewayUrl()
458
+ {
459
+ return $this->_getGatewayUrl().'rates';
460
+
461
+ }
462
+
463
+ /**
464
+ * Retrieve url for getting shipping rates
465
+ * @return string
466
+ */
467
+ public function getValidationGatewayUrl()
468
+ {
469
+ return $this->_getGatewayUrl().'address/validation';
470
+
471
+ }
472
+
473
+ /*
474
+ * *Retrieve url for retrieving attributes
475
+ */
476
+ public function getAttributeGatewayUrl()
477
+ {
478
+ return $this->_getGatewayUrl().'attributes/get';
479
+ }
480
+
481
+ /*
482
+ * *Retrieve url for retrieving attributes
483
+ */
484
+ public function getCheckSynchronizedUrl()
485
+ {
486
+ return $this->_getGatewayUrl().'attributes/check';
487
+ }
488
+
489
+ /*
490
+ * *Retrieve url for retrieving attributes
491
+ */
492
+ public function getSetSynchronizedUrl()
493
+ {
494
+ return $this->_getGatewayUrl().'attributes/set/updated';
495
+ }
496
+
497
+ /*
498
+ * *Retrieve url for reserving order details
499
+ */
500
+ public function getReserveOrderGatewayUrl()
501
+ {
502
+ return $this->_getGatewayUrl().'order/reserve';
503
+ }
504
+
505
+ /*
506
+ * *Retrieve url for confirming order
507
+ */
508
+ public function getConfirmOrderGatewayUrl()
509
+ {
510
+ return $this->_getGatewayUrl().'order/confirm';
511
+ }
512
+
513
+ /*
514
+ * *Retrieve url for creating shipment
515
+ */
516
+ public function getCreateShipmentGatewayUrl()
517
+ {
518
+ return $this->_getGatewayUrl().'shipment/create';
519
+ }
520
+
521
+ /*
522
+ * *Retrieve url for retrieving shipment add-on details
523
+ */
524
+ public function getShipmentAddonGatewayUrl()
525
+ {
526
+ return $this->_getGatewayUrl().'shipment/addon';
527
+ }
528
+
529
+ /*
530
+ * Retrieve configured timeout for webservice
531
+ */
532
+ public function getWebserviceTimeout()
533
+ {
534
+
535
+ if (self::$_wsTimeout==NULL) {
536
+ $timeout = Mage::getStoreConfig('carriers/shipper/ws_timeout');
537
+ if(!is_numeric($timeout) || $timeout < 120) {
538
+ $timeout = 120;
539
+ }
540
+ self::$_wsTimeout = $timeout;
541
+ }
542
+ return self::$_wsTimeout;
543
+ }
544
+
545
+ /**
546
+ * Saves the carrier title to core_config_data
547
+ * Need to do this as doesnt read from the shipping rate quote table!
548
+ * @param $carrierCode
549
+ * @param $carrierTitle
550
+ */
551
+ public function saveCarrierTitle($carrierCode,$carrierTitle)
552
+ {
553
+ $this->saveConfig('carriers/'.$carrierCode.'/title',$carrierTitle);
554
+ }
555
+
556
+ /**
557
+ * Save config value to db
558
+ * @param $path
559
+ * @param $value
560
+ * @param string $scope
561
+ * @param int $scopeId
562
+ * @return $this
563
+ */
564
+ public function saveConfig($path, $value, $scope = 'default', $scopeId = 0)
565
+ {
566
+ if (Mage::getStoreConfig($path) != $value) {
567
+ Mage::getConfig()->saveConfig(rtrim($path, '/'), $value, $scope, $scopeId);
568
+ Mage::helper('shipperhq_shipper')->getQuoteStorage()->setConfigUpdated(true);
569
+ }
570
+ }
571
+
572
+ public function encodeShippingDetails($shippingDetails)
573
+ {
574
+ return Zend_Json::encode($shippingDetails);
575
+ }
576
+
577
+ public function decodeShippingDetails($shippingDetailsEnc)
578
+ {
579
+ return Zend_Json::decode($shippingDetailsEnc);
580
+ }
581
+
582
+ /**
583
+ * Retrieve checkout quote model object
584
+ *
585
+ * @return Mage_Sales_Model_Quote
586
+ */
587
+ public function getQuote()
588
+ {
589
+ if ($this->_quote !== null) {
590
+ return $this->_quote;
591
+ }
592
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
593
+ if(!$quote->getId()) {
594
+ $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
595
+ }
596
+ return $quote;
597
+
598
+ }
599
+
600
+ /**
601
+ * Overrides quote model
602
+ *
603
+ * @param Mage_Sales_Model_Quote|null $quote
604
+ * @return $this
605
+ */
606
+ public function setQuote($quote)
607
+ {
608
+ $this->_quote = $quote;
609
+ return $this;
610
+ }
611
+
612
+ public function isSortOnPrice()
613
+ {
614
+ return $this->getGlobalSetting('sortBasedPrice');
615
+ }
616
+
617
+ public function getGlobalSetting($code)
618
+ {
619
+ $globals = Mage::helper('shipperhq_shipper')->getGlobalSettings();
620
+ if(!is_null($globals) && array_key_exists($code, $globals)
621
+ && $globals[$code] != '') {
622
+ return $globals[$code];
623
+ }
624
+ return false;
625
+ }
626
+
627
+ /*
628
+ * Retrieve global settings saved to session
629
+ *
630
+ * @return array
631
+ */
632
+ public function getGlobalSettings()
633
+ {
634
+ return $this->getQuoteStorage($this->getQuote())->getShipperGlobal();
635
+ }
636
+
637
+ /**
638
+ * Get a date format from global settings
639
+ *
640
+ * @param string $date
641
+ * @return bool|string
642
+ */
643
+ public static function getDateFormat()
644
+ {
645
+ if (self::$_dateFormat==NULL) {
646
+ $globals = Mage::helper('shipperhq_shipper')->getGlobalSettings();
647
+ if( !is_null($globals) && array_key_exists('preferredLocale', $globals) && $globals['preferredLocale'] != '') {
648
+ if($globals['preferredLocale'] == 'en-US') {
649
+ $rawDateFormat = 'mm/dd/yyyy';
650
+ }
651
+ else {
652
+ $rawDateFormat = 'dd-mm-yyyy';
653
+ }
654
+ }
655
+ else {
656
+ $rawDateFormat = 'mm/dd/yyyy';
657
+ }
658
+ self::$_dateFormat =
659
+ Mage::getModel('shipperhq_shipper/carrier_shipper')->getCode('date_format', $rawDateFormat);
660
+ }
661
+ return self::$_dateFormat;
662
+ }
663
+
664
+ /**
665
+ * Get a date format in Zend format
666
+ *
667
+ * @param string $date
668
+ * @return bool|string
669
+ */
670
+ public static function getZendDateFormat()
671
+ {
672
+ if (self::$_zendDateFormat==NULL) {
673
+ $globals = Mage::helper('shipperhq_shipper')->getGlobalSettings();
674
+ if( !is_null($globals) && array_key_exists('preferredLocale', $globals) && $globals['preferredLocale'] != '') {
675
+ if($globals['preferredLocale'] == 'en-US') {
676
+ $rawDateFormat = 'mm/dd/yyyy';
677
+ }
678
+ else {
679
+ $rawDateFormat = 'dd-mm-yyyy';
680
+ }
681
+ }
682
+ else {
683
+ $rawDateFormat = 'mm/dd/yyyy';
684
+ }
685
+ self::$_zendDateFormat =
686
+ Mage::getModel('shipperhq_shipper/carrier_shipper')->getCode('zend_date_format', $rawDateFormat);
687
+ }
688
+ return self::$_zendDateFormat;
689
+ }
690
+
691
+ /**
692
+ * Get a date format for calendar widget display
693
+ *
694
+ * @param string $date
695
+ * @return bool|string
696
+ */
697
+ public static function getDatepickerFormat()
698
+ {
699
+ if (self::$_datepickerFormat==NULL) {
700
+ $globals = Mage::helper('shipperhq_shipper')->getGlobalSettings();
701
+ if( !is_null($globals) && array_key_exists('preferredLocale', $globals) && $globals['preferredLocale'] != '') {
702
+ if($globals['preferredLocale'] == 'en-US') {
703
+ $rawDateFormat = 'mm/dd/yyyy';
704
+ }
705
+ else {
706
+ $rawDateFormat = 'dd-mm-yyyy';
707
+ }
708
+ }
709
+ else {
710
+ $rawDateFormat = 'mm/dd/yyyy';
711
+ }
712
+ self::$_datepickerFormat =
713
+ Mage::getModel('shipperhq_shipper/carrier_shipper')->getCode('datepicker_format', $rawDateFormat);
714
+ }
715
+ return self::$_datepickerFormat;
716
+ }
717
+
718
+ /**
719
+ * Get a date format in short format
720
+ *
721
+ * @param string $date
722
+ * @return bool|string
723
+ */
724
+ public static function getShortDateFormat()
725
+ {
726
+ if (self::$_shortDateFormat==NULL) {
727
+ $globals = Mage::helper('shipperhq_shipper')->getGlobalSettings();
728
+ if(!is_null($globals) && array_key_exists('dateFormat', $globals) && $globals['dateFormat'] != '') {
729
+ $rawDateFormat = $globals['dateFormat'];
730
+ }
731
+ else {
732
+ $rawDateFormat = 'mm/dd/yyyy';
733
+ }
734
+ self::$_shortDateFormat =
735
+ Mage::getModel('shipperhq_shipper/carrier_shipper')->getCode('short_date_format', $rawDateFormat);
736
+ }
737
+ return self::$_shortDateFormat;
738
+ }
739
+
740
+ public function showPickupConfirm()
741
+ {
742
+ return $this->getGlobalSetting('calendarConfirm');
743
+ }
744
+
745
+ public function isPickupRate($address, $shippingMethodChosen)
746
+ {
747
+ if(!$this->isModuleEnabled('Shipperhq_Pickup')) {
748
+ return false;
749
+ }
750
+ $rate = $address->getShippingRateByCode($shippingMethodChosen);
751
+ if($rate && Mage::helper('shipperhq_pickup')->isPickupEnabledCarrier($rate->getCarrierType())) {
752
+ return $rate->getCarrier();
753
+ }
754
+ return false;
755
+ }
756
+
757
+ /*
758
+ *
759
+ */
760
+ public function getOurCarrierCode()
761
+ {
762
+ return Mage::getModel('shipperhq_shipper/carrier_shipper')->getCarrierCode();
763
+ }
764
+
765
+ public function mapToMagentoCarrierCode($carrierType, $carrierCode)
766
+ {
767
+ if(array_key_exists($carrierType, $this->magentoCarrierCodes)) {
768
+ return $this->magentoCarrierCodes[$carrierType];
769
+ }
770
+ return $carrierCode;
771
+ }
772
+
773
+ public function refreshConfig()
774
+ {
775
+ if(Mage::helper('shipperhq_shipper')->getQuoteStorage()->getConfigUpdated()) {
776
+ Mage::app()->getStore()->resetConfig();
777
+ Mage::helper('shipperhq_shipper')->getQuoteStorage()->setConfigUpdated(false);
778
+ }
779
+ }
780
+
781
+ public function isCityEnabled()
782
+ {
783
+ if($this->isModuleEnabled('Shipperhq_Lookup') && Mage::helper('shipperhq_lookup')->isPostcodeAutocompleteEnabled()) {
784
+ return true;
785
+ }
786
+ $cityRequired = $this->getGlobalSetting('cityRequired');
787
+ if(!$cityRequired) {
788
+ $cityRequired = Mage::getStoreConfig('carriers/shipper/CARRIER_CITY_REQUIRED_DEFAULT');
789
+ }
790
+ return $cityRequired;
791
+ }
792
+
793
+ public function isCityRequired()
794
+ {
795
+ return $this->isCityEnabled();
796
+ }
797
+
798
+ public function isAccessorialsEnabled()
799
+ {
800
+ return Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Freight');
801
+ }
802
+ /**
803
+ *
804
+ * @return array
805
+ */
806
+ public function getProductAttributes()
807
+ {
808
+ if(is_null($this->_prodAttributes)) {
809
+ /** @var $eavConfig Mage_Eav_Model_Config */
810
+ $eavConfig = Mage::getSingleton('eav/config');
811
+
812
+ $this->_prodAttributes = $eavConfig->getEntityAttributeCodes(Mage_Catalog_Model_Product::ENTITY);
813
+ }
814
+
815
+ return $this->_prodAttributes;
816
+ }
817
+
818
+ public function getProductsWithAttributeValue($attribute_code, $value, $storeId = null, $isSelect = false, $returnCount = true)
819
+ {
820
+ if($isSelect) {
821
+ $value = $this->_getOptionId($this->getAttribute($attribute_code, $storeId), $value);
822
+ }
823
+ $collection = Mage::getModel('catalog/product')->setStoreId($storeId)->getCollection();
824
+ if(!is_null($storeId) && $storeId != '') {
825
+ $collection->addStoreFilter((int)$storeId);
826
+ }
827
+
828
+ $collection->addAttributeToSelect($attribute_code);
829
+ $collection->addFieldToFilter(array(
830
+ array('attribute'=>$attribute_code,'finset'=>$value),
831
+ ));
832
+ if($returnCount) {
833
+ return count($collection);
834
+ }
835
+
836
+ return $collection;
837
+ }
838
+
839
+ public function extractAddressIdAndCarriergroupId(&$addressId, &$carrierGroupId)
840
+ {
841
+ if(strstr($carrierGroupId, 'ma')) {
842
+ $addressId = str_replace('ma', '', $carrierGroupId);
843
+ $carrierGroupId = '';
844
+ if(strstr($addressId, 'ZZ')) {
845
+ $idArray = explode('ZZ', $addressId);
846
+ $addressId = $idArray[0];
847
+ $carrierGroupId = $idArray[1];
848
+ }
849
+ }
850
+ }
851
+
852
+ public function isOscDropdowns()
853
+ {
854
+ if($this->isModuleEnabled('Idev_OneStepCheckout')
855
+ && Mage::getStoreConfig('onestepcheckout/general/condense_shipping_methods')) {
856
+ return true;
857
+ }
858
+ return false;
859
+ }
860
+
861
+ public function isConfirmOrderRequired($carrierType)
862
+ {
863
+ return $carrierType == 'gso';
864
+ }
865
+
866
+ public function getCarriergroupShippingHtml($encodedDetails)
867
+ {
868
+ $decodedDetails = Mage::helper('shipperhq_shipper')->decodeShippingDetails($encodedDetails);
869
+ $htmlText='<br/>';
870
+ foreach ($decodedDetails as $shipLine) {
871
+
872
+ if(!is_array($shipLine) || !array_key_exists('name', $shipLine)) {
873
+ continue;
874
+ }
875
+ $htmlText .= $shipLine['name'].
876
+ ' : '.$shipLine['carrierTitle'].' - '. $shipLine['methodTitle'].' ';
877
+ $htmlText .= " ". $this->getQuote()->getStore()->formatPrice($shipLine['price']).'<br/>';
878
+ if(array_key_exists('pickup_date', $shipLine)) {
879
+ $htmlText .= Mage::helper('shipperhq_shipper')->__('Location') .' : ' .$shipLine['location_name'];
880
+ $htmlText .= Mage::helper('shipperhq_shipper')->__(' Date') .' : ' .$shipLine['pickup_date'];
881
+ if(array_key_exists('pickup_slot', $shipLine)) {
882
+ $htmlText .= Mage::helper('shipperhq_shipper')->__(' Time : ') .str_replace('_', ' - ', $shipLine['pickup_slot']);
883
+ }
884
+ $htmlText.= '<br/>';
885
+ }
886
+ else if(array_key_exists('delivery_date', $shipLine)) {
887
+ $htmlText .= Mage::helper('shipperhq_shipper')->__(' Delivery Date') .' : ' .$shipLine['delivery_date'];
888
+ if(array_key_exists('del_slot', $shipLine)) {
889
+ $htmlText .= Mage::helper('shipperhq_shipper')->__(' Time : ') .str_replace('_', ' - ',$shipLine['del_slot']);
890
+ }
891
+ $htmlText.= '<br/>';
892
+ }
893
+
894
+ }
895
+ return $htmlText;
896
+ }
897
+
898
+ public function setShippingOnItems($shippingDetails, $shippingAddress)
899
+ {
900
+ $itemsGrouped = $this->getItemsGroupedByCarrierGroup($shippingAddress->getAllItems());
901
+ foreach($shippingDetails as $carrierGroupDetail)
902
+ {
903
+ if(is_array($carrierGroupDetail) && array_key_exists('carrierTitle', $carrierGroupDetail)) {
904
+ $carrierGroupId = $carrierGroupDetail['carrierGroupId'];
905
+ $shippingText = $carrierGroupDetail['carrierTitle'] .' - ' .$carrierGroupDetail['methodTitle'];
906
+ if(array_key_exists('delivery_date', $carrierGroupDetail)) {
907
+ $shippingText .= ' Delivery: ' .$carrierGroupDetail['delivery_date'];
908
+ }
909
+ if(array_key_exists('dispatch_date', $carrierGroupDetail)) {
910
+ $shippingText .= ' Dispatch: ' .$carrierGroupDetail['dispatch_date'];
911
+ }
912
+ // if(array_key_exists('time_slot'))
913
+ if(array_key_exists($carrierGroupId, $itemsGrouped)) {
914
+ foreach($itemsGrouped[$carrierGroupId] as $item) {
915
+ $item->setCarriergroupShipping($shippingText);
916
+ }
917
+ }
918
+
919
+
920
+ }
921
+
922
+ }
923
+ }
924
+
925
+ /**
926
+ * Format items based on carrier group
927
+ *
928
+ * @return array
929
+ */
930
+ public function getItemsGroupedByCarrierGroup($cartItems)
931
+ {
932
+ $groupedItems = array();
933
+ foreach($cartItems as $item)
934
+ {
935
+ if(array_key_exists($item->getCarriergroupId(), $groupedItems)) {
936
+ $groupedItems[$item->getCarriergroupId()][] = $item;
937
+ }
938
+ else {
939
+ $groupedItems[$item->getCarriergroupId()]= array($item);
940
+ }
941
+ }
942
+
943
+ return $groupedItems;
944
+ }
945
+
946
+ public function cleanDownRatesCollection($address, $carrierCode, $carriergroupId)
947
+ {
948
+ $currentRates = $address->getGroupedAllShippingRates();
949
+ foreach($currentRates as $code => $rates)
950
+ {
951
+ if($code == $carrierCode){
952
+ foreach($rates as $rate) {
953
+ if($carriergroupId == '' || $rate->getCarriergroupId() == $carriergroupId) {
954
+ $rate->isDeleted(true);
955
+ }
956
+ }
957
+ }
958
+
959
+ }
960
+ }
961
+
962
+ protected function _getOptionId($attribute, $value)
963
+ {
964
+ //get the source
965
+ $source = $attribute->getSource();
966
+ //get the id
967
+ $id = $source->getOptionId($value);
968
+ return $id;
969
+ }
970
+
971
+ protected function getAttribute($attribute_code, $store = null) {
972
+ $attribute = Mage::getResourceModel('catalog/product')
973
+ ->getAttribute($attribute_code);
974
+
975
+ if(is_null($store) || $store == '') {
976
+ $store = Mage_Core_Model_App::ADMIN_STORE_ID;
977
+ }
978
+ $attribute->setStoreId($store);
979
+
980
+ return $attribute;
981
+ }
982
+
983
+ protected function _dynamicCarrierConfig($carrierCode, $carrierType, $carrierTitle, $sortOrder = false)
984
+ {
985
+ $modelPath = 'carriers/'.$carrierCode.'/model';
986
+ if(!Mage::getStoreConfig($modelPath)) {
987
+ if($this->isModuleEnabled('Shipperhq_Pickup') &&
988
+ Mage::helper('shipperhq_pickup')->isPickupEnabledCarrier($carrierType)) {
989
+ $model = 'shipperhq_pickup/carrier_storepickup';
990
+ } else {
991
+ $model = 'shipperhq_shipper/carrier_shipper';
992
+ }
993
+ $this->saveConfig($modelPath, $model);
994
+ $this->saveConfig('carriers/'.$carrierCode.'/active', 0);
995
+ }
996
+ $this->saveCarrierTitle($carrierCode, $carrierTitle);
997
+
998
+ if($sortOrder) {
999
+ $this->saveConfig('carriers/'.$carrierCode.'/sort_order', $sortOrder);
1000
+ }
1001
+
1002
+
1003
+ }
1004
+
1005
+ /**
1006
+ * Returns url to use - live if present, otherwise dev
1007
+ * @return array
1008
+ */
1009
+ protected function _getGatewayUrl()
1010
+ {
1011
+ $live = $this->_cleanUpUrl(Mage::getStoreConfig('carriers/shipper/live_url'));
1012
+
1013
+ $test = $this->_cleanUpUrl(Mage::getStoreConfig('carriers/shipper/url'));
1014
+ return Mage::getStoreConfig('carriers/shipper/sandbox_mode') ? $test : $live;
1015
+ }
1016
+
1017
+ protected function _cleanUpUrl($urlStart)
1018
+ {
1019
+ $url = trim($urlStart);
1020
+ $lastChar = substr("abcdef", -1);
1021
+ if($lastChar != '/') {
1022
+ $url .= '/';
1023
+ }
1024
+ return $url;
1025
+ }
1026
+ }
app/code/community/Shipperhq/Shipper/Helper/Mapper.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mapper for a data arrays tranformation
5
+ */
6
+ class Shipperhq_Shipper_Helper_Mapper
7
+ extends Mage_Core_Helper_Abstract
8
+ {
9
+ /**
10
+ * Maps data by specified rules
11
+ *
12
+ * @param array $mapping
13
+ * @param array $source
14
+ * @return array
15
+ */
16
+ public function map($mapping, $source)
17
+ {
18
+ $target = array();
19
+ foreach ($mapping as $targetField => $sourceField) {
20
+ if (is_string($sourceField)) {
21
+ if (strpos($sourceField, '/') !== false) {
22
+ $fields = explode('/', $sourceField);
23
+ $value = $source;
24
+ while ($fields) {
25
+ $field = array_shift($fields);
26
+ if (isset($value[$field])) {
27
+ $value = $value[$field];
28
+ } else {
29
+ $value = null;
30
+ break;
31
+ }
32
+ }
33
+ $target[$targetField] = $value;
34
+ } else {
35
+ $target[$targetField] = $source[$sourceField];
36
+ }
37
+ } elseif (is_array($sourceField)) {
38
+ list($field, $defaultValue) = $sourceField;
39
+ $target[$targetField] = (isset($source[$field]) ? $source[$field] : $defaultValue);
40
+ } elseif ($sourceField instanceof Closure) {
41
+ $mapping = $sourceField($source);
42
+ $target[$targetField] = $mapping;
43
+ }
44
+ }
45
+
46
+ return $target;
47
+ }
48
+ }
app/code/community/Shipperhq/Shipper/Model/Adminhtml/System/Config/Source/Carriers.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Adminhtml_System_Config_Source_Carriers extends Mage_Core_Model_Abstract {
32
+
33
+ public function toOptionArray() {
34
+
35
+ $arr = array();
36
+
37
+ $storeId = Mage::app()->getStore()->getStoreId() ;
38
+
39
+ $carriers = Mage::getSingleton('shipping/config')->getAllCarriers($storeId);
40
+
41
+ foreach ($carriers as $carrierCode=>$carrierModel) {
42
+ $carrierTitle = Mage::getStoreConfig('carriers/' . $carrierCode . '/title', $storeId);
43
+ if (strpos($carrierCode, 'shipper') === 0 || $carrierTitle == '') {
44
+ continue;
45
+ }
46
+ if(Mage::getStoreConfig('carriers/'.$carrierCode.'/model') == 'shipperhq_shipper/carrier_shipper') {
47
+ continue;
48
+ }
49
+ $arr[] = array('value' => $carrierCode, 'label' => $carrierTitle);
50
+ }
51
+ array_unshift($arr, array('value' => false, 'label' => Mage::helper('shipping')->__('No Carrier')));
52
+
53
+ return $arr;
54
+
55
+ }
56
+
57
+ }
app/code/community/Shipperhq/Shipper/Model/Adminhtml/System/Config/Source/Environmentscope.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Class Shipperhq_Shipper_Model_Adminhtml_System_Config_Source_Environmentscope
33
+ *
34
+ * This class provides options for environment scope to configuration
35
+ *
36
+ */
37
+
38
+ include_once 'ShipperHQ/User/SiteDetails.php';
39
+
40
+ class Shipperhq_Shipper_Model_Adminhtml_System_Config_Source_Environmentscope {
41
+
42
+ public function toOptionArray()
43
+ {
44
+ return array(
45
+ array(
46
+ 'value' => \ShipperHQ\User\SiteDetails::LIVE,
47
+ 'label' => Mage::helper('shipperhq_shipper')->__('Live')
48
+ ),
49
+ array(
50
+ 'value' => \ShipperHQ\User\SiteDetails::DEV,
51
+ 'label' => Mage::helper('shipperhq_shipper')->__('Development')
52
+ ),
53
+ array(
54
+ 'value' => \ShipperHQ\User\SiteDetails::TEST,
55
+ 'label' => Mage::helper('shipperhq_shipper')->__('Test')
56
+ ),
57
+ array(
58
+ 'value' => \ShipperHQ\User\SiteDetails::INTEGRATION,
59
+ 'label' => Mage::helper('shipperhq_shipper')->__('Integration')
60
+ ),
61
+ );
62
+ }
63
+ }
app/code/community/Shipperhq/Shipper/Model/Attributeupdate.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Attributeupdate extends Mage_Core_Model_Abstract
32
+ {
33
+
34
+ public function _construct()
35
+ {
36
+ parent::_construct();
37
+ $this->_init('shipperhq_shipper/attributeupdate');
38
+ $this->setIdFieldName('synch_id');
39
+ }
40
+
41
+ }
app/code/community/Shipperhq/Shipper/Model/Carrier/Backup.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Shipper shipping model
33
+ *
34
+ * @category ShipperHQ
35
+ * @package ShipperHQ_Shipper
36
+ */
37
+
38
+ class Shipperhq_Shipper_Model_Carrier_Backup extends Mage_Core_Model_Abstract
39
+ {
40
+
41
+ protected $storeId;
42
+ protected $availabilityConfigField = 'active';
43
+
44
+ public function getBackupCarrierRates($request)
45
+ {
46
+ $this->storeId = $request->getStoreId();
47
+ $carrierCode = $this->getBackupCarrierDetails();
48
+ if(!$carrierCode) {
49
+ return false;
50
+ }
51
+
52
+ $tempEnabledCarrier = $this->tempSetCarrierEnabled($carrierCode,true);
53
+ $carrier = $this->getCarrierByCode($carrierCode, $request->getStoreId());
54
+
55
+ if (!$carrier) {
56
+ $this->tempSetCarrierEnabled($carrierCode,false);
57
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
58
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Unable to activate backup carrier',
59
+ $carrierCode);
60
+ }
61
+ return false;
62
+ }
63
+
64
+ $result = $carrier->collectRates($request);
65
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
66
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Backup carrier result: ',
67
+ $result);
68
+ }
69
+
70
+ if ($tempEnabledCarrier) {
71
+ $this->tempSetCarrierEnabled($carrierCode,false);
72
+ }
73
+ return $result;
74
+
75
+ }
76
+
77
+ /**
78
+ * Enable or disable carrier
79
+ * @return boolean
80
+ */
81
+ protected function tempSetCarrierEnabled ($carrierCode,$enabled)
82
+ {
83
+ $carrierPath='carriers/'.$carrierCode.'/'.$this->availabilityConfigField;
84
+ return $this->setEnabledConfig($carrierPath, $enabled);
85
+ }
86
+
87
+ protected function setEnabledConfig($path, $enabled)
88
+ {
89
+ $store = Mage::app()->getStore();
90
+ $tempEnabled = false;
91
+
92
+ if (!Mage::getStoreConfigFlag($path) || !$enabled) { // if $enabled set to false was previously enabled!
93
+ $store->setConfig($path,$enabled);
94
+ $tempEnabled = true;
95
+ }
96
+
97
+ return $tempEnabled;
98
+ }
99
+
100
+ /**
101
+ * Get backup carrier if configured
102
+ * @return mixed
103
+ */
104
+ protected function getBackupCarrierDetails() {
105
+ $carrierDetails = Mage::getStoreConfig('carriers/shipper/backup_carrier', $this->storeId);
106
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
107
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Unable to establish connection with ShipperHQ',
108
+ 'Attempting to use backup carrier: ' .$carrierDetails);
109
+ }
110
+ if(!$carrierDetails) {
111
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
112
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'Backup carrier: ',
113
+ 'No backup carrier is configured');
114
+ }
115
+ return false;
116
+ }
117
+ return $carrierDetails;
118
+ }
119
+
120
+ /**
121
+ * Get carrier by its code
122
+ *
123
+ * @param string $carrierCode
124
+ * @param null|int $storeId
125
+ * @return bool|Mage_Core_Model_Abstract
126
+ */
127
+ public function getCarrierByCode($carrierCode, $storeId = null)
128
+ {
129
+ if (!Mage::getStoreConfigFlag('carriers/'.$carrierCode.'/'.$this->availabilityConfigField, $storeId)) {
130
+ return false;
131
+ }
132
+ $className = Mage::getStoreConfig('carriers/'.$carrierCode.'/model', $storeId);
133
+ if (!$className) {
134
+ return false;
135
+ }
136
+ $obj = Mage::getModel($className);
137
+ if ($storeId) {
138
+ $obj->setStore($storeId);
139
+ }
140
+ return $obj;
141
+ }
142
+ }
app/code/community/Shipperhq/Shipper/Model/Carrier/Convert/AddressMapper.php ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Class Shipperhq_Shipper_Model_Carrier_Convert_QuoteMapper
33
+ *
34
+ * This class converts the Magento Request into a format that
35
+ * is usable by the ShipperHQ webservice
36
+ */
37
+
38
+ include_once 'ShipperHQ/User/Credentials.php';
39
+ include_once 'ShipperHQ/User/SiteDetails.php';
40
+ include_once 'ShipperHQ/WS/Request/Rate/CustomerDetails.php';
41
+ include_once 'ShipperHQ/WS/Request/Rate/ShipDetails.php';
42
+ include_once 'ShipperHQ/WS/Request/Rate/RateRequest.php';
43
+ include_once 'ShipperHQ/WS/Request/Rate/InfoRequest.php';
44
+ include_once 'ShipperHQ/Shipping/Address.php';
45
+ include_once 'ShipperHQ/Shipping/Accessorials.php';
46
+
47
+
48
+ class Shipperhq_Shipper_Model_Carrier_Convert_AddressMapper extends Shipperhq_Shipper_Model_Carrier_Convert_ShipperMapper {
49
+
50
+
51
+ function __construct() {
52
+ self::$_prodAttributes = Mage::helper('shipperhq_shipper')->getProductAttributes();
53
+ }
54
+ /**
55
+ * Set up values for ShipperHQ Rates Request
56
+ *
57
+ * @param $magentoRequest
58
+ * @return string
59
+ */
60
+ public static function getAddressTranslation($address, $carrierCode = null, $carrierGroupId = null)
61
+ {
62
+
63
+ $shipperHQRequest = new \ShipperHQ\WS\Request\Rate\RateRequest(
64
+ self::getCartDetails($address),
65
+ self::getDestination($address),
66
+ self::getCustomerGroupDetails($address),
67
+ self::getCartType($address)
68
+ );
69
+
70
+ if($carrierGroupId) {
71
+ $shipperHQRequest->setCarrierGroupId($carrierGroupId);
72
+ }
73
+
74
+ if($carrierCode) {
75
+ $shipperHQRequest->setCarrierCode($carrierCode);
76
+ }
77
+ $storeId = $address->getQuote()->getStoreId();
78
+ $shipperHQRequest->setSiteDetails(self::getSiteDetails($storeId));
79
+ $shipperHQRequest->setCredentials(self::getCredentials($storeId));
80
+
81
+ return $shipperHQRequest;
82
+ }
83
+
84
+ /**
85
+ * Format cart for from shipper for Magento
86
+ *
87
+ * @param $request
88
+ * @return array
89
+ */
90
+ public static function getCartDetails($address)
91
+ {
92
+ $cart = array();
93
+ $cart['declaredValue'] = (int)$address->getSubtotal();
94
+ $cart['freeShipping'] = null;
95
+ $cart['items'] = self::getFormattedItems($address->getAllItems());
96
+
97
+ // $cart['additional_attributes'] = null; // not currently implemented
98
+
99
+ return $cart;
100
+ }
101
+
102
+ /*
103
+ * Return customer group details
104
+ *
105
+ */
106
+ public static function getCustomerGroupDetails($address)
107
+ {
108
+ $code = $address->getQuote()->getCustomerGroupId();
109
+ $group = Mage::getModel('customer/group')->load($code);
110
+
111
+ $custGroupDetails = new \ShipperHQ\WS\Request\Rate\CustomerDetails(
112
+ $group->getCustomerGroupCode()
113
+ );
114
+
115
+ return $custGroupDetails;
116
+ }
117
+
118
+ /*
119
+ * Return cartType String default
120
+ *
121
+ */
122
+ public static function getCartType($address)
123
+ {
124
+ return 'STD';
125
+ }
126
+
127
+
128
+ /**
129
+ * Get values for items
130
+ *
131
+ * @param $request
132
+ * @param $magentoItems
133
+ * @param bool $childItems
134
+ * @param null $taxPercentage
135
+ * @return array
136
+ */
137
+ private static function getFormattedItems($magentoItems, $childItems = false, $taxPercentage = null)
138
+ {
139
+ $formattedItems = array();
140
+ if (empty($magentoItems)) {
141
+ return $formattedItems;
142
+ }
143
+ $selectedCarriergroupId = false;
144
+
145
+ foreach ($magentoItems as $magentoItem) {
146
+ if (!$childItems && $magentoItem->getParentItemId()) {
147
+ continue;
148
+ }
149
+
150
+ $calculator = Mage::helper('tax')->getCalculator();
151
+ $taxRequest = $calculator->getRateOriginRequest();
152
+ $taxRequest->setProductClassId($magentoItem->getProduct()->getTaxClassId());
153
+ $taxPercentage = $calculator->getRate($taxRequest);
154
+ $fixedPrice = $magentoItem->getProduct()->getPriceType() == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED;
155
+ $fixedWeight = $magentoItem->getProduct()->getWeightType() == 1 ? true : false;
156
+ $id = $magentoItem->getItemId()? $magentoItem->getItemId() : $magentoItem->getQuoteItemId();
157
+ $productType = $magentoItem->getProductType()? $magentoItem->getProductType() : $magentoItem->getProduct()->getTypeId();
158
+ $stdAttributes = array_merge(self::getDimensionalAttributes($magentoItem), self::$_stdAttributeNames);
159
+
160
+ $formattedItem = array(
161
+ 'id' => $id,
162
+ 'sku' => $magentoItem->getSku(),
163
+ 'storePrice' => $magentoItem->getPrice(),
164
+ 'weight' => $magentoItem->getWeight(),
165
+ 'qty' => floatval($magentoItem->getQty()),
166
+ 'type' => $productType,
167
+ 'items' => array(), // child items
168
+ 'basePrice' => $magentoItem->getBasePrice(),
169
+ 'taxInclBasePrice' => $magentoItem->getBasePriceInclTax()? $magentoItem->getBasePriceInclTax(): 0,
170
+ 'taxInclStorePrice' => $magentoItem->getPriceInclTax() ? $magentoItem->getPriceInclTax() : 0,
171
+ 'rowTotal' => $magentoItem->getRowTotal(),
172
+ 'baseRowTotal' => $magentoItem->getBaseRowTotal(),
173
+ 'discountPercent' => $magentoItem->getDiscountPercent(),
174
+ 'discountedBasePrice' => $magentoItem->getBasePrice() - ($magentoItem->getBaseDiscountAmount()/$magentoItem->getQty()),
175
+ 'discountedStorePrice' => $magentoItem->getPrice() - ($magentoItem->getDiscountAmount()/$magentoItem->getQty()),
176
+ 'discountedTaxInclBasePrice' => $magentoItem->getBasePrice() - ($magentoItem->getBaseDiscountAmount()/$magentoItem->getQty()) + ($magentoItem->getBaseTaxAmount()/$magentoItem->getQty()),
177
+ 'discountedTaxInclStorePrice' => $magentoItem->getPrice() - ($magentoItem->getDiscountAmount()/$magentoItem->getQty()) + ($magentoItem->getTaxAmount()/$magentoItem->getQty()),
178
+ 'attributes' => self::populateAttributes($stdAttributes, $magentoItem),
179
+ 'legacyAttributes' => self::populateAttributes(self::$_legacyAttributeNames, $magentoItem),
180
+ 'baseCurrency' => Mage::app()->getBaseCurrencyCode(),//$request->getBaseCurrency()->getCurrencyCode(),
181
+ 'packageCurrency' => Mage::app()->getBaseCurrencyCode(), //$request->getPackageCurrency()->getCurrencyCode(),
182
+ 'storeBaseCurrency' => Mage::app()->getBaseCurrencyCode(),
183
+ 'storeCurrentCurrency' => Mage::app()->getStore()->getCurrentCurrencyCode(),
184
+ 'taxPercentage' => $taxPercentage,
185
+ 'freeShipping' => (bool)$magentoItem->getFreeShipping(),
186
+ 'additionalAttributes' => self::getCustomAttributes($magentoItem),
187
+ 'fixedPrice' => $fixedPrice,
188
+ 'fixedWeight' => $fixedWeight,
189
+ );
190
+
191
+ if (!$childItems) {
192
+ $formattedItem['items'] = self::getFormattedItems(
193
+ $magentoItem->getChildren(), true, null );
194
+ }
195
+
196
+ $formattedItems[] = $formattedItem;
197
+
198
+ }
199
+ return $formattedItems;
200
+ }
201
+
202
+ /**
203
+ * Get values for destination
204
+ *
205
+ * @param $request
206
+ * @return array
207
+ */
208
+ private static function getDestination($shippingAddress)
209
+ {
210
+ $selectedOptions = self::getSelectedOptions($shippingAddress);
211
+ $streetArray = $shippingAddress->getStreet();
212
+ $street2 = isset($streetArray[1]) ? $streetArray[1] : '';
213
+ $destination = new \ShipperHQ\Shipping\Address(
214
+ null,
215
+ $shippingAddress->getCity(),
216
+ $shippingAddress->getCountryId(),
217
+ $shippingAddress->getRegionCode(),
218
+ $streetArray[0],
219
+ $street2,
220
+ $shippingAddress->getPostcode(),
221
+ $shippingAddress->getEmail(),
222
+ $shippingAddress->getFirstname(),
223
+ $shippingAddress->getLastname(),
224
+ $shippingAddress->getCompany(),
225
+ $shippingAddress->getTelephone(),
226
+ $selectedOptions
227
+ );
228
+
229
+ return $destination;
230
+ }
231
+
232
+ /**
233
+ * Set up additional attribute array
234
+ * This takes the values from core_config_data
235
+ *
236
+ * Not currently implemented for v1 Magento2.
237
+ *
238
+ * @param $item
239
+ * @return array
240
+ */
241
+ private static function getCustomAttributes($item)
242
+ {
243
+ $rawCustomAttributes = explode(',', Mage::getStoreConfig('carriers/shipper/item_attributes'));
244
+ $customAttributes = array();
245
+ foreach ($rawCustomAttributes as $attribute) {
246
+ $attribute = str_replace(' ', '', $attribute);
247
+ if(!in_array($attribute, self::$_stdAttributeNames) && !in_array($attribute, self::$_legacyAttributeNames) && $attribute != '') {
248
+ $customAttributes[] = $attribute;
249
+ }
250
+ }
251
+
252
+ return self::populateAttributes($customAttributes,$item);
253
+
254
+ }
255
+
256
+ }
app/code/community/Shipperhq/Shipper/Model/Carrier/Convert/OrderMapper.php ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Class Shipperhq_Shipper_Model_Carrier_Convert_ShipperMapper
33
+ *
34
+ * This class converts the Magento Request into a format that
35
+ * is usable by the ShipperHQ webservice
36
+ */
37
+
38
+ include_once 'ShipperHQ/User/Credentials.php';
39
+ include_once 'ShipperHQ/User/SiteDetails.php';
40
+ include_once 'ShipperHQ/WS/Request/Rate/ShipmentCustomerDetails.php';
41
+ include_once 'ShipperHQ/WS/Request/Rate/ShipmentRequest.php';
42
+ include_once 'ShipperHQ/Shipping/Address.php';
43
+
44
+
45
+ class Shipperhq_Shipper_Model_Carrier_Convert_OrderMapper extends Shipperhq_Shipper_Model_Carrier_Convert_ShipperMapper
46
+ {
47
+
48
+ protected static $ecommerceType = 'magento';
49
+
50
+ /**
51
+ * Set up values for ShipperHQ Shipment Request
52
+ *
53
+ * @param $order
54
+ * @return string
55
+ */
56
+ public static function getOrderTranslation($order, $quote, $customOrderId = null)
57
+ {
58
+
59
+ $shipperHQRequest = new \ShipperHQ\WS\Request\Rate\ShipmentRequest(
60
+ self::getShipmentItems($order),
61
+ self::getShippingAddress($order),
62
+ self::getBillingAddress($order),
63
+ self::getCustomerDetails($order, $quote),
64
+ self::getCarrierCode($quote, $order),
65
+ self::getMagentoOrderNumber($order),
66
+ $customOrderId,
67
+ self::getOriginName($order),
68
+ self::getMethodCode($order)
69
+ );
70
+ $shippingAddress = $quote->getShippingAddress();
71
+ $storeId = $quote->getStoreId();
72
+ $shipperHQRequest->setSiteDetails(self::getSiteDetails($storeId));
73
+ $shipperHQRequest->setCredentials(self::getCredentials($storeId));
74
+
75
+ return $shipperHQRequest;
76
+ }
77
+
78
+ /**
79
+ * Format cart for from shipper for Magento
80
+ *
81
+ * @param $request
82
+ * @return array
83
+ */
84
+ public static function getShipmentItems($order)
85
+ {
86
+ $shipmentItems = false;
87
+ //TODO we need to support CarrierGroupId here
88
+ // loadByCarriergroup($orderId, $carrierGroupId)
89
+ $packagesColl= Mage::getModel('shipperhq_shipper/order_packages')
90
+ ->loadByOrderId($order->getId());
91
+ $mapping = self::getPackagesMapping();
92
+ if($packagesColl) {
93
+ $shipmentItems = array();
94
+ foreach($packagesColl as $package) {
95
+ $data = Mage::helper('shipperhq_shipper/mapper')->map($mapping,(array)$package->getData());
96
+ $data['boxedItems'] = self::appendAdditionalAttributes($data['boxedItems']);
97
+ $shipmentItems[] = $data;
98
+ }
99
+ }
100
+ return $shipmentItems;
101
+ }
102
+
103
+ public static function appendAdditionalAttributes($itemData)
104
+ {
105
+ $newItemData = array();
106
+ foreach($itemData as $item)
107
+ {
108
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item['sku']);
109
+ // dont want package_id
110
+ $data['sku'] = $item['sku'];
111
+ $data['weightPacked'] = $item['weight_packed'];
112
+ $data['qtyPacked'] = $item['qty_packed'];
113
+ if($product) {
114
+ $countryArray = array('name' => 'country_of_manufacture',
115
+ 'value' => $product->getData('country_of_manufacture'));
116
+ $data['shippingAttributes'] = array($countryArray);
117
+ }
118
+ $newItemData[] = $data;
119
+ }
120
+ return $newItemData;
121
+ }
122
+ /*
123
+ * Return customer group details
124
+ *
125
+ */
126
+ public static function getCustomerDetails($order, $quote)
127
+ {
128
+ $code = self::getCustomerGroupId($quote);
129
+ $group = Mage::getModel('customer/group')->load($code);
130
+ $billingAddress = $order->getBillingAddress();
131
+ $custGroupDetails = new \ShipperHQ\WS\Request\Rate\ShipmentCustomerDetails(
132
+ $group->getCustomerGroupCode(), $billingAddress->getCompany(), $order->getCustomerEmail(), $order->getCustomerFirstname(),
133
+ $order->getCustomerLastname(), $billingAddress->getTelephone()
134
+ );
135
+
136
+ return $custGroupDetails;
137
+ }
138
+
139
+
140
+ /*
141
+ * Return selected carrierGroup id
142
+ */
143
+ public static function getCarrierGroupId($request)
144
+ {
145
+ $carrierGroupId = $request->getCarriergroupId();
146
+ return $carrierGroupId;
147
+ }
148
+ /*
149
+ * Return selected carrier id
150
+ *
151
+ */
152
+ public static function getCarrierCode($quote, $order)
153
+ {
154
+ $carrierCode = null;
155
+ $shippingMethod = $order->getShippingMethod();
156
+
157
+ $rate = $quote->getShippingAddress()->getShippingRateByCode($shippingMethod);
158
+ if($rate) {
159
+ $carrierCode = $rate->getCarrier();
160
+ }
161
+ else{
162
+ $carrierArray = explode('_', $shippingMethod);
163
+ $carrierCode = $carrierArray[0];
164
+ }
165
+
166
+ return $carrierCode;
167
+ }
168
+
169
+ protected static function getPackagesMapping()
170
+ {
171
+ return array(
172
+ 'name' => 'package_name',
173
+ 'length' => 'length',
174
+ 'width' => 'width',
175
+ 'height' => 'height',
176
+ 'weight' => 'weight',
177
+ 'surchargePrice' => 'surcharge_price',
178
+ 'declaredValue' => 'declared_value',
179
+ 'boxedItems' => 'items'
180
+ );
181
+ }
182
+
183
+ protected static function getCustomerGroupId($quote)
184
+ {
185
+ if($quote) {
186
+ return $quote->getCustomerGroupId();
187
+ }
188
+ return null;
189
+ }
190
+
191
+ /**
192
+ * Get values for destination
193
+ *
194
+ * @param $request
195
+ * @return array
196
+ */
197
+ private static function getShippingAddress($order)
198
+ {
199
+ $shippingAddress = $order->getShippingAddress();
200
+
201
+ $streetArray = $shippingAddress->getStreet();
202
+ $street2 = isset($streetArray[1]) ? $streetArray[1] : null;
203
+ $destination = new \ShipperHQ\Shipping\Address(
204
+ null,
205
+ $shippingAddress->getCity(),
206
+ $shippingAddress->getCountryId(),
207
+ $shippingAddress->getRegionCode(),
208
+ $streetArray[0],
209
+ $street2,
210
+ $shippingAddress->getPostcode(),
211
+ $shippingAddress->getEmail(),
212
+ $shippingAddress->getFirstname(),
213
+ $shippingAddress->getLastname(),
214
+ $shippingAddress->getCompany(),
215
+ $shippingAddress->getTelephone(),
216
+ null
217
+ );
218
+ return $destination;
219
+ }
220
+
221
+ /**
222
+ * Get values for destination
223
+ *
224
+ * @param $request
225
+ * @return array
226
+ */
227
+ private static function getBillingAddress($order)
228
+ {
229
+ $billingAddress = $order->getBillingAddress();
230
+
231
+ $streetArray = $billingAddress->getStreet();
232
+ $street2 = isset($streetArray[1]) ? $streetArray[1] : null;
233
+ $address = new \ShipperHQ\Shipping\Address(
234
+ null,
235
+ $billingAddress->getCity(),
236
+ $billingAddress->getCountryId(),
237
+ $billingAddress->getRegionCode(),
238
+ $streetArray[0],
239
+ $street2,
240
+ $billingAddress->getPostcode(),
241
+ $billingAddress->getEmail(),
242
+ $billingAddress->getFirstname(),
243
+ $billingAddress->getLastname(),
244
+ $billingAddress->getCompany(),
245
+ $billingAddress->getTelephone(),
246
+ null
247
+ );
248
+ return $address;
249
+ }
250
+
251
+ protected static function getOriginName($order)
252
+ {
253
+ $carrierGroupDetail = $order->getCarriergroupShippingDetails();
254
+ if($carrierGroupDetail) {
255
+ $cgDetail = json_decode($carrierGroupDetail);
256
+ foreach($cgDetail as $carrierGroup) {
257
+ if(!is_array($carrierGroup)) {
258
+ $carrierGroup = (array)$carrierGroup;
259
+ }
260
+ return $carrierGroup['name'];
261
+ }
262
+ }
263
+ return null;
264
+ }
265
+
266
+ protected static function getMethodCode($order)
267
+ {
268
+ $shipmethod = explode('_', $order->getShippingMethod());
269
+ if(is_array($shipmethod)) {
270
+ return $shipmethod[1];
271
+ }
272
+ return null;
273
+ }
274
+ }
app/code/community/Shipperhq/Shipper/Model/Carrier/Convert/ShipmentMapper.php ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Class Shipperhq_Shipper_Model_Carrier_Convert_ShipperMapper
33
+ *
34
+ * This class converts the Magento Request into a format that
35
+ * is usable by the ShipperHQ webservice
36
+ */
37
+
38
+ include_once 'ShipperHQ/User/Credentials.php';
39
+ include_once 'ShipperHQ/User/SiteDetails.php';
40
+ include_once 'ShipperHQ/WS/Request/Rate/ShipmentAddonRequest.php';
41
+
42
+
43
+ class Shipperhq_Shipper_Model_Carrier_Convert_ShipmentMapper extends Shipperhq_Shipper_Model_Carrier_Convert_ShipperMapper
44
+ {
45
+
46
+ protected static $ecommerceType = 'magento';
47
+
48
+ /**
49
+ * Set up values for ShipperHQ Shipment Request
50
+ *
51
+ * @param $order
52
+ * @return string
53
+ */
54
+ public static function getShipmentTranslation($order, $shipment, $package, $customOrderId = null)
55
+ {
56
+
57
+ $shipperHQRequest = new \ShipperHQ\WS\Request\Rate\ShipmentAddonRequest(
58
+ self::getShipmentItems($package),
59
+ self::getCarrierCode($order),
60
+ self::getDomesticShipper($order),
61
+ self::getMethodCode($order),
62
+ self::getMagentoOrderNumber($order),
63
+ self::getOriginName($order),
64
+ $customOrderId,
65
+ self::getTrackingNo($shipment)
66
+ );
67
+ $storeId = $order->getStoreId();
68
+ $shipperHQRequest->setSiteDetails(self::getSiteDetails($storeId));
69
+ $shipperHQRequest->setCredentials(self::getCredentials($storeId));
70
+
71
+ return $shipperHQRequest;
72
+ }
73
+
74
+ /**
75
+ * Format cart for from shipper for Magento
76
+ *
77
+ * @param $request
78
+ * @return array
79
+ */
80
+ public static function getShipmentItems($package)
81
+ {
82
+ $shipmentItems = false;
83
+ //TODO we need to support CarrierGroupId here
84
+ if($package) {
85
+ $mapping = self::getPackagesMapping();
86
+ $data = Mage::helper('shipperhq_shipper/mapper')->map($mapping,(array)$package->getData());
87
+ $data['boxedItems'] = self::appendAdditionalAttributes($data['boxedItems']);
88
+ $shipmentItems = $data;
89
+ }
90
+ return $shipmentItems;
91
+ }
92
+
93
+ public static function appendAdditionalAttributes($itemData)
94
+ {
95
+ $newItemData = array();
96
+ foreach($itemData as $item)
97
+ {
98
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item['sku']);
99
+ $data['sku'] = $item['sku'];
100
+ $data['weightPacked'] = $item['weight_packed'];
101
+ $data['qtyPacked'] = $item['qty_packed'];
102
+ if($product) {
103
+ $countryArray = array('name' => 'country_of_manufacture',
104
+ 'value' => $product->getData('country_of_manufacture'));
105
+ $data['shippingAttributes'] = array($countryArray);
106
+ }
107
+ $newItemData[] = $data;
108
+ }
109
+ return $newItemData;
110
+ }
111
+
112
+ public static function getCarrierCode($order)
113
+ {
114
+ $carrierCode = null;
115
+
116
+ $shipMethod = $order->getShippingMethod();
117
+ $shipArray = explode('_', $shipMethod);
118
+ if(is_array($shipArray)) {
119
+ $carrierCode = $shipArray[0];
120
+ }
121
+ return $carrierCode;
122
+ }
123
+
124
+ public static function getMethodCode($order)
125
+ {
126
+ $methodCode = null;
127
+ $shipMethod = $order->getShippingMethod();
128
+ $shipArray = explode('_', $shipMethod);
129
+ if(is_array($shipArray)) {
130
+ $methodCode = $shipArray[1];
131
+ }
132
+ return $methodCode;
133
+ }
134
+
135
+ /**
136
+ * Domestic tracking number
137
+ * @param $shipment
138
+ * @return string
139
+ */
140
+ public static function getTrackingNo($shipment)
141
+ {
142
+ foreach($shipment->getTracksCollection() as $track) {
143
+ return $track->getNumber();
144
+ }
145
+ return 'Not Set';
146
+ }
147
+
148
+ /**
149
+ * Domestic carrier
150
+ *
151
+ * @param $shipment
152
+ * @return string
153
+ */
154
+ public static function getDomesticShipper($shipment)
155
+ {
156
+ foreach($shipment->getTracksCollection() as $track) {
157
+ return $track->getTitle();
158
+ }
159
+ return 'Not Set';
160
+ }
161
+
162
+ public static function getOriginName($order)
163
+ {
164
+ $carrierGroupDetail = $order->getCarriergroupShippingDetails();
165
+ if($carrierGroupDetail) {
166
+ $cgDetail = json_decode($carrierGroupDetail);
167
+ foreach($cgDetail as $carrierGroup) {
168
+ if(!is_array($carrierGroup)) {
169
+ $carrierGroup = (array)$carrierGroup;
170
+ }
171
+ return $carrierGroup['name'];
172
+ }
173
+ }
174
+ return null;
175
+ }
176
+
177
+ protected static function getPackagesMapping()
178
+ {
179
+ return array(
180
+ 'name' => 'package_name',
181
+ 'length' => 'length',
182
+ 'width' => 'width',
183
+ 'height' => 'height',
184
+ 'weight' => 'weight',
185
+ 'surchargePrice' => 'surcharge_price',
186
+ 'declaredValue' => 'declared_value',
187
+ 'boxedItems' => 'items'
188
+ );
189
+ }
190
+
191
+ }
app/code/community/Shipperhq/Shipper/Model/Carrier/Convert/ShipperMapper.php ADDED
@@ -0,0 +1,671 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Class Shipperhq_Shipper_Model_Carrier_Convert_ShipperMapper
33
+ *
34
+ * This class converts the Magento Request into a format that
35
+ * is usable by the ShipperHQ webservice
36
+ */
37
+
38
+ include_once 'ShipperHQ/User/Credentials.php';
39
+ include_once 'ShipperHQ/User/SiteDetails.php';
40
+ include_once 'ShipperHQ/WS/Request/Rate/CustomerDetails.php';
41
+ include_once 'ShipperHQ/WS/Request/Rate/ShipDetails.php';
42
+ include_once 'ShipperHQ/WS/Request/Rate/RateRequest.php';
43
+ include_once 'ShipperHQ/WS/Request/Rate/InfoRequest.php';
44
+ include_once 'ShipperHQ/Shipping/Address.php';
45
+ include_once 'ShipperHQ/Shipping/Accessorials.php';
46
+ include_once 'ShipperHQ/Shipping/SelectedOptions.php';
47
+
48
+
49
+
50
+ class Shipperhq_Shipper_Model_Carrier_Convert_ShipperMapper {
51
+
52
+
53
+ protected static $ecommerceType = 'magento';
54
+ protected static $_stdAttributeNames = array(
55
+ 'shipperhq_shipping_group', 'shipperhq_post_shipping_group',
56
+ 'shipperhq_warehouse', 'shipperhq_royal_mail_group', 'shipperhq_shipping_qty',
57
+ 'shipperhq_shipping_fee','shipperhq_additional_price','freight_class',
58
+ 'shipperhq_nmfc_class', 'shipperhq_nmfc_sub', 'shipperhq_handling_fee','shipperhq_carrier_code',
59
+ 'shipperhq_volume_weight', 'shipperhq_declared_value', 'ship_separately','shipperhq_malleable_product',
60
+ 'shipperhq_dim_group', 'shipperhq_poss_boxes', 'shipperhq_master_boxes', 'ship_box_tolerance', 'must_ship_freight', 'packing_section_name'
61
+ );
62
+
63
+ protected static $dim_height = 'ship_height';
64
+ protected static $dim_width = 'ship_width';
65
+ protected static $dim_length = 'ship_length';
66
+ protected static $alt_height = 'height';
67
+ protected static $alt_width = 'width';
68
+ protected static $alt_length = 'length';
69
+
70
+ protected static $_useDefault = 'Use Default';
71
+
72
+ protected static $dim_group = 'shipperhq_dim_group';
73
+ protected static $conditional_dims = array('shipperhq_poss_boxes', 'shipperhq_master_boxes',
74
+ 'shipperhq_volume_weight', 'ship_box_tolerance', 'ship_separately'
75
+ );
76
+
77
+ protected static $_legacyAttributeNames = array(
78
+ 'package_id', 'special_shipping_group', 'volume_weight', 'warehouse', 'handling_id',
79
+ 'package_type' // royal mail
80
+ );
81
+
82
+ protected static $_shippingOptions = array('liftgate_required', 'notify_required', 'inside_delivery', 'destination_type');
83
+
84
+ protected static $_prodAttributes;
85
+
86
+ function __construct() {
87
+ self::$_prodAttributes = Mage::helper('shipperhq_shipper')->getProductAttributes();
88
+ }
89
+ /**
90
+ * Set up values for ShipperHQ Rates Request
91
+ *
92
+ * @param $magentoRequest
93
+ * @return string
94
+ */
95
+ public static function getShipperTranslation($magentoRequest)
96
+ {
97
+
98
+ $shipperHQRequest = new \ShipperHQ\WS\Request\Rate\RateRequest(
99
+ self::getCartDetails($magentoRequest),
100
+ self::getDestination($magentoRequest),
101
+ self::getCustomerGroupDetails($magentoRequest),
102
+ self::getCartType($magentoRequest)
103
+ );
104
+ if($delDate = self::getDeliveryDateUTC($magentoRequest)) {
105
+ $shipperHQRequest->setDeliveryDate(self::getDeliveryDate($magentoRequest));
106
+ $shipperHQRequest->setDeliveryDateUTC($delDate);
107
+ }
108
+ if($shipDetails = self::getShipDetails($magentoRequest)) {
109
+ $shipperHQRequest->setShipDetails($shipDetails);
110
+ }
111
+ if($carrierGroupId = self::getCarrierGroupId($magentoRequest)) {
112
+ $shipperHQRequest->setCarrierGroupId($carrierGroupId);
113
+ }
114
+
115
+ if($carrierId = self::getCarrierId($magentoRequest)) {
116
+ $shipperHQRequest->setCarrierId($carrierId);
117
+ }
118
+
119
+ $storeId = $magentoRequest->getStore();
120
+ $shipperHQRequest->setSiteDetails(self::getSiteDetails($storeId));
121
+ $shipperHQRequest->setCredentials(self::getCredentials($storeId));
122
+
123
+ return $shipperHQRequest;
124
+ }
125
+
126
+ /**
127
+ * Set up values for ShipperHQ getAllowedMethods()
128
+ *
129
+ * @return string
130
+ */
131
+ public static function getCredentialsTranslation($storeId = null)
132
+ {
133
+ $shipperHQRequest = new \ShipperHQ\WS\Request\Rate\InfoRequest();
134
+ $shipperHQRequest->setCredentials(self::getCredentials($storeId));
135
+ $shipperHQRequest->setSiteDetails(self::getSiteDetails($storeId));
136
+ return $shipperHQRequest;
137
+ }
138
+
139
+
140
+ /**
141
+ * Return credentials for ShipperHQ login
142
+ *
143
+ * @return array
144
+ */
145
+ public static function getCredentials($storeId = null)
146
+ {
147
+
148
+ $credentials = new \ShipperHQ\User\Credentials(Mage::getStoreConfig('carriers/shipper/api_key', $storeId),
149
+ Mage::getStoreConfig('carriers/shipper/password', $storeId));
150
+ return $credentials;
151
+ }
152
+
153
+ /**
154
+ * Format cart for from shipper for Magento
155
+ *
156
+ * @param $request
157
+ * @return array
158
+ */
159
+ public static function getCartDetails($request)
160
+ {
161
+ $cart = array();
162
+ $cart['declaredValue'] = $request->getPackageValue();
163
+ $cart['freeShipping'] = (bool)$request->getFreeShipping();
164
+ $cart['items'] = self::getFormattedItems($request,$request->getAllItems());
165
+
166
+ // $cart['additional_attributes'] = null; // not currently implemented
167
+
168
+ return $cart;
169
+ }
170
+
171
+
172
+ /**
173
+ * Return site specific information
174
+ *
175
+ * @return array
176
+ */
177
+ public static function getSiteDetails($storeId = null)
178
+ {
179
+ $edition = 'Community';
180
+ if(method_exists('Mage', 'getEdition')) {
181
+ $edition = Mage::getEdition();
182
+ }
183
+ elseif(Mage::helper('wsalogger')->isEnterpriseEdition()) {
184
+ $edition = 'Enterprise';
185
+ }
186
+ $url = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
187
+ $siteDetails = new \ShipperHQ\User\SiteDetails('Magento ' . $edition, Mage::getVersion(),
188
+ $url, Mage::getStoreConfig('carriers/shipper/environment_scope', $storeId),
189
+ (string)Mage::getConfig()->getNode('modules/Shipperhq_Shipper/extension_version'));
190
+
191
+ return $siteDetails;
192
+ }
193
+
194
+ /*
195
+ * Return customer group details
196
+ *
197
+ */
198
+ public static function getCustomerGroupDetails($request)
199
+ {
200
+ $code = self::getCustomerGroupId($request->getAllItems());
201
+ $group = Mage::getModel('customer/group')->load($code);
202
+
203
+ $custGroupDetails = new \ShipperHQ\WS\Request\Rate\CustomerDetails(
204
+ $group->getCustomerGroupCode()
205
+ );
206
+
207
+ return $custGroupDetails;
208
+ }
209
+
210
+ /*
211
+ * Return ship Details selected
212
+ *
213
+ */
214
+ public static function getShipDetails($request)
215
+ {
216
+ $pickupId = self::getLocation($request);
217
+ if($pickupId != '') {
218
+ $shipDetails = new \ShipperHQ\WS\Request\Rate\ShipDetails(
219
+ $pickupId
220
+ );
221
+
222
+ return $shipDetails;
223
+ }
224
+ return false;
225
+ }
226
+
227
+ /*
228
+ * Return cartType String
229
+ *
230
+ */
231
+ public static function getCartType($request)
232
+ {
233
+ $cartType = $request->getCartType();
234
+ return $cartType;
235
+ }
236
+
237
+ /*
238
+ * Return Delivery Date selected
239
+ *
240
+ */
241
+ public static function getDeliveryDateUTC($request)
242
+ {
243
+ $timeStamp = $request->getDeliveryDateSelected();
244
+ if(!is_null($timeStamp)) {
245
+ $inMilliseconds = $timeStamp * 1000;
246
+ return $inMilliseconds;
247
+ }
248
+ return null;
249
+ }
250
+
251
+ public static function getDeliveryDate($request)
252
+ {
253
+ return $request->getDeliveryDate();
254
+ }
255
+
256
+ /*
257
+ * Return pickup location selected
258
+ *
259
+ */
260
+ public static function getLocation($request)
261
+ {
262
+ $selectedLocationId = $request->getLocationSelected();
263
+ return $selectedLocationId;
264
+ }
265
+
266
+ /*
267
+ * Return selected carrierGroup id
268
+ */
269
+ public static function getCarrierGroupId($request)
270
+ {
271
+ $carrierGroupId = $request->getCarriergroupId();
272
+ return $carrierGroupId;
273
+ }
274
+ /*
275
+ * Return selected carrier id
276
+ *
277
+ */
278
+ public static function getCarrierId($request)
279
+ {
280
+ $carrierId = $request->getCarrierId();
281
+ return $carrierId;
282
+ }
283
+
284
+ /**
285
+ * Get values for items
286
+ *
287
+ * @param $request
288
+ * @param $magentoItems
289
+ * @param bool $childItems
290
+ * @param null $taxPercentage
291
+ * @return array
292
+ */
293
+ private static function getFormattedItems($request,$magentoItems, $childItems = false, $taxPercentage = null)
294
+ {
295
+ $formattedItems = array();
296
+ if (empty($magentoItems)) {
297
+ return $formattedItems;
298
+ }
299
+ $selectedCarriergroupId = false;
300
+
301
+ if($request->getCarriergroupId() != '') {
302
+ $selectedCarriergroupId = $request->getCarriergroupId();
303
+ }
304
+ foreach ($magentoItems as $magentoItem) {
305
+
306
+ $childPrices = array();
307
+
308
+ if (!$childItems && ($magentoItem->getParentItemId() || $magentoItem->getParentItem())) {
309
+ continue;
310
+ }
311
+
312
+ //strip out items not required in carriergroup specific request
313
+ if($selectedCarriergroupId && $magentoItem->getCarriergroupId() != $selectedCarriergroupId) {
314
+ continue;
315
+ }
316
+
317
+ $calculator = Mage::helper('tax')->getCalculator();
318
+ $taxRequest = $calculator->getRateOriginRequest();
319
+ $taxRequest->setProductClassId($magentoItem->getProduct()->getTaxClassId());
320
+ $taxPercentage = $calculator->getRate($taxRequest);
321
+ $fixedPrice = $magentoItem->getProduct()->getPriceType() == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED;
322
+ $fixedWeight = $magentoItem->getProduct()->getWeightType() == 1 ? true : false;
323
+ $id = $magentoItem->getItemId()? $magentoItem->getItemId() : $magentoItem->getQuoteItemId();
324
+ $productType = $magentoItem->getProductType()? $magentoItem->getProductType() : $magentoItem->getProduct()->getTypeId();
325
+ $stdAttributes = array_merge(self::getDimensionalAttributes($magentoItem), self::$_stdAttributeNames);
326
+ $options = self::populateCustomOptions($magentoItem);
327
+ $weight = $magentoItem->getWeight();
328
+ if($productType!= Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL && is_null($weight)) { //SHIPPERHQ-1855
329
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
330
+ Mage::helper('wsalogger/log')->postCritical('ShipperHQ','Item weight is null, using 0',
331
+ 'Please review the product configuration for Sku ' .$magentoItem->getSku() .' as product has NULL weight');
332
+ }
333
+ $weight = 0;
334
+ }
335
+ if(is_null($id)) {
336
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
337
+ Mage::helper('wsalogger/log')->postCritical('ShipperHQ','Item ID is null',
338
+ 'Please review the product configuration for Sku ' .$magentoItem->getSku() .' as product has NULL item ID');
339
+ }
340
+ }
341
+ $formattedItem = array(
342
+ 'id' => $id,
343
+ 'sku' => $magentoItem->getSku(),
344
+ 'storePrice' => $magentoItem->getPrice() ? $magentoItem->getPrice() : 0,
345
+ 'weight' => $weight,
346
+ 'qty' => $magentoItem->getQty() ? floatval($magentoItem->getQty()): 0,
347
+ 'type' => $productType,
348
+ 'items' => array(), // child items
349
+ 'basePrice' => $magentoItem->getBasePrice(),
350
+ 'taxInclBasePrice' => $magentoItem->getBasePriceInclTax()? $magentoItem->getBasePriceInclTax(): 0,
351
+ 'taxInclStorePrice' => $magentoItem->getPriceInclTax() ? $magentoItem->getPriceInclTax() : 0,
352
+ 'rowTotal' => $magentoItem->getRowTotal(),
353
+ 'baseRowTotal' => $magentoItem->getBaseRowTotal(),
354
+ 'discountPercent' => $magentoItem->getDiscountPercent(),
355
+ 'discountedBasePrice' => $magentoItem->getBasePrice() - ($magentoItem->getBaseDiscountAmount()/$magentoItem->getQty()),
356
+ 'discountedStorePrice' => $magentoItem->getPrice() - ($magentoItem->getDiscountAmount()/$magentoItem->getQty()),
357
+ 'discountedTaxInclBasePrice' => $magentoItem->getBasePrice() - ($magentoItem->getBaseDiscountAmount()/$magentoItem->getQty()) + ($magentoItem->getBaseTaxAmount()/$magentoItem->getQty()),
358
+ 'discountedTaxInclStorePrice' => $magentoItem->getPrice() - ($magentoItem->getDiscountAmount()/$magentoItem->getQty()) + ($magentoItem->getTaxAmount()/$magentoItem->getQty()),
359
+ 'attributes' => $options? array_merge(self::populateAttributes($stdAttributes, $magentoItem), $options) : self::populateAttributes($stdAttributes, $magentoItem),
360
+ 'legacyAttributes' => self::populateAttributes(self::$_legacyAttributeNames, $magentoItem),
361
+ 'baseCurrency' => $request->getBaseCurrency()->getCurrencyCode(),
362
+ 'packageCurrency' => $request->getPackageCurrency()->getCurrencyCode(),
363
+ 'storeBaseCurrency' => Mage::app()->getBaseCurrencyCode(),
364
+ 'storeCurrentCurrency' => Mage::app()->getStore()->getCurrentCurrencyCode(),
365
+ 'taxPercentage' => $taxPercentage,
366
+ 'freeShipping' => (bool)$magentoItem->getFreeShipping(),
367
+ 'additionalAttributes' => self::getCustomAttributes($magentoItem),
368
+ 'fixedPrice' => $fixedPrice,
369
+ 'fixedWeight' => $fixedWeight,
370
+ );
371
+
372
+ if (!$childItems) {
373
+ $formattedItem['items'] = self::getFormattedItems(
374
+ $request, $magentoItem->getChildren(), true, null );
375
+ }
376
+
377
+ if($productType == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $fixedPrice) {
378
+ $formattedItem['storePrice'] = $magentoItem->getProduct()->getPrice();
379
+ }
380
+
381
+ /**
382
+ * SHIPPERHQ-1833
383
+ */
384
+ if($magentoItem->getParentItem()) {
385
+ $parentProduct = $magentoItem->getParentItem()->getProduct();
386
+
387
+ if($parentProduct->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE &&
388
+ $parentProduct->getPriceType() == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) {
389
+
390
+ $childPrices = self::getBundleChildPrices($magentoItem);
391
+
392
+ $discountPercent = $formattedItem['discountPercent'];
393
+ $discountDifference = $discountPercent != 0 ? (100 - $discountPercent) / 100 : 1;
394
+
395
+ $formattedItem['storePrice'] = $childPrices['storePrice'];
396
+ $formattedItem['basePrice'] = $childPrices['basePrice'];
397
+ $formattedItem['taxInclBasePrice'] = $childPrices['taxInclBasePrice'];
398
+ $formattedItem['taxInclStorePrice'] = $childPrices['taxInclStorePrice'];
399
+ $formattedItem['rowTotal'] = $childPrices['storePrice'] * $magentoItem->getQty();
400
+ $formattedItem['baseRowTotal'] = $childPrices['basePrice'] * $magentoItem->getQty();
401
+ $formattedItem['discountedBasePrice'] = $childPrices['basePrice'] * $discountDifference;
402
+ $formattedItem['discountedStorePrice'] = $childPrices['storePrice'] * $discountDifference;
403
+ $formattedItem['discountedTaxInclBasePrice'] = $childPrices['taxInclBasePrice'] * $discountDifference;
404
+ $formattedItem['discountedTaxInclStorePrice'] = $childPrices['taxInclStorePrice'] * $discountDifference;
405
+ }
406
+ }
407
+
408
+ $formattedItems[] = $formattedItem;
409
+
410
+ }
411
+ return $formattedItems;
412
+ }
413
+
414
+ private static function getBundleChildPrices($magentoItem)
415
+ {
416
+ $parentProduct = $magentoItem->getParentItem()->getProduct();
417
+ $parentQty = $magentoItem->getParentItem()->getQty();
418
+ $bundleChildPrices = array();
419
+
420
+ if ($parentProduct->hasCustomOptions()) {
421
+ $customOption = $parentProduct->getCustomOption('bundle_selection_ids');
422
+ $selectionIds = unserialize($customOption->getValue());
423
+ $selections = $parentProduct->getTypeInstance(true)->getSelectionsByIds($selectionIds, $parentProduct);
424
+ if (method_exists($selections,'addTierPriceData')) {
425
+ $selections->addTierPriceData();
426
+ }
427
+ foreach ($selections->getItems() as $selection) {
428
+ if ($selection->getProductId() == $magentoItem->getProductId()) {
429
+ //Looks like Magento isn't multiplying the child item price by the qty, Confirmed in 1.6-1.7
430
+ $bundleChildPrices['basePrice'] = ($parentProduct->getPriceModel()->getChildFinalPrice(
431
+ $parentProduct, $magentoItem->getParentItem()->getQty(),
432
+ $selection, /*$finalTotals->getQty()**/$magentoItem->getParentItem()->getQty(), $magentoItem->getQty()) * $magentoItem->getQty()) * $parentQty;
433
+
434
+ //Price from here is always base. Convert to store to stay consistent unless flag $useBase is set.
435
+ $bundleChildPrices['storePrice'] = Mage::helper('directory')->currencyConvert($bundleChildPrices['basePrice'],
436
+ Mage::app()->getStore()->getBaseCurrencyCode(),
437
+ Mage::app()->getStore()->getCurrentCurrencyCode());
438
+
439
+
440
+ $calculator = Mage::helper('tax')->getCalculator();
441
+ $taxRequest = $calculator->getRateOriginRequest();
442
+ $taxRequest->setProductClassId($parentProduct->getTaxClassId());
443
+ $taxPercentage = $calculator->getRate($taxRequest);
444
+
445
+ $bundleChildPrices['taxInclBasePrice'] = ($bundleChildPrices['basePrice'] + round(($taxPercentage/100) * $bundleChildPrices['basePrice'],2));;
446
+ $bundleChildPrices['taxInclStorePrice'] = round(Mage::helper('directory')->currencyConvert($bundleChildPrices['taxInclBasePrice'],
447
+ Mage::app()->getStore()->getBaseCurrencyCode(), Mage::app()->getStore()->getCurrentCurrencyCode()),2);
448
+ }
449
+ }
450
+ }
451
+
452
+ return $bundleChildPrices;
453
+ }
454
+
455
+ protected static function getCustomerGroupId($items)
456
+ {
457
+ if(count($items) > 0) {
458
+ return $items[0]->getQuote()->getCustomerGroupId();
459
+ }
460
+ return null;
461
+ }
462
+
463
+ /**
464
+ * Get values for destination
465
+ *
466
+ * @param $request
467
+ * @return array
468
+ */
469
+ private static function getDestination($request)
470
+ {
471
+
472
+ $selectedOptions = self::getSelectedOptions($request);
473
+
474
+ if (self::getCartType($request)=="CART") {
475
+ // Don't pass in street for this scenario
476
+ $destination = new \ShipperHQ\Shipping\Address(
477
+ null,
478
+ $request->getDestCity(),
479
+ $request->getDestCountryId(),
480
+ $request->getDestRegionCode(),
481
+ null,
482
+ null,
483
+ $request->getDestPostcode(),
484
+ null,
485
+ null,
486
+ null,
487
+ null,
488
+ null,
489
+ $selectedOptions
490
+ );
491
+ } else {
492
+ $destination = new \ShipperHQ\Shipping\Address(
493
+ null,
494
+ $request->getDestCity(),
495
+ $request->getDestCountryId(),
496
+ $request->getDestRegionCode(),
497
+ $request->getDestStreet(),
498
+ null,
499
+ $request->getDestPostcode(),
500
+ null,
501
+ null,
502
+ null,
503
+ null,
504
+ null,
505
+ $selectedOptions
506
+ );
507
+ }
508
+
509
+ return $destination;
510
+ }
511
+
512
+ protected static function getDimensionalAttributes($item)
513
+ {
514
+ $attributes = array();
515
+ $product = $item->getProduct();
516
+ if(in_array(self::$dim_length, self::$_prodAttributes) && $product->getData(self::$dim_length) != '') {
517
+ $attributes = array(self::$dim_length, self::$dim_height, self::$dim_width);
518
+ }
519
+ elseif(in_array(self::$alt_length, self::$_prodAttributes) && $product->getData(self::$alt_length) != '') {
520
+ $attributes = array(self::$alt_length, self::$alt_height, self::$alt_width);
521
+ }
522
+ return $attributes;
523
+ }
524
+
525
+ /**
526
+ * Reads attributes from the item
527
+ *
528
+ * @param $reqdAttributeNames
529
+ * @param $item
530
+ * @return array
531
+ */
532
+ protected static function populateAttributes($reqdAttributeNames,$item)
533
+ {
534
+ $attributes = array();
535
+ $product = $item->getProduct();
536
+
537
+
538
+ if(!in_array(self::$dim_group, self::$_prodAttributes)) {
539
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
540
+ Mage::helper('wsalogger/log')->postWarning('ShipperHQ',self::$dim_group .' attribute does not exist',
541
+ 'Review installation to ensure latest version is installed and SQL install script has completed');
542
+ }
543
+ }
544
+ elseif($product->getAttributeText(self::$dim_group) != '') {
545
+ $reqdAttributeNames = array_diff($reqdAttributeNames, self::$conditional_dims);
546
+ }
547
+
548
+ foreach ($reqdAttributeNames as $attributeName) {
549
+
550
+ $attribute = $product->getResource()->getAttribute($attributeName);
551
+ if ($attribute) {
552
+ $attributeType = $attribute->getFrontendInput();
553
+ } else {
554
+ continue;
555
+ }
556
+ if ($attributeType == 'select' || $attributeType == 'multiselect') {
557
+ $attributeString = $product->getData($attribute->getAttributeCode());
558
+ $attributeValue = explode(',', $attributeString);
559
+ if(is_array($attributeValue)) {
560
+ $valueString = array();
561
+ foreach($attributeValue as $aValue) {
562
+ $admin_value= $attribute->setStoreId(0)->getSource()->getOptionText($aValue);
563
+ $valueString[]= is_array($admin_value) ? implode('', $admin_value) : $admin_value;
564
+ }
565
+ $attributeValue = implode('#', $valueString);
566
+ }
567
+ else {
568
+ $attributeValue= $attribute->setStoreId(0)->getSource()->getOptionText($attributeValue);
569
+ }
570
+ } else {
571
+ $attributeValue = $product->getData($attributeName);
572
+ }
573
+
574
+ if (!empty($attributeValue) && !strstr($attributeValue,self::$_useDefault)) {
575
+ $attributes[] = array (
576
+ 'name' => $attributeName,
577
+ 'value' => $attributeValue
578
+ );
579
+ }
580
+ }
581
+
582
+ return $attributes;
583
+ }
584
+
585
+ /**
586
+ * Reads attributes from the item
587
+ * SHIPPERHQ-1598
588
+ *
589
+ * @param $item
590
+ * @return array
591
+ */
592
+ protected static function populateCustomOptions($item)
593
+ {
594
+ $option_labels = array();
595
+ $options = Mage::helper('catalog/product_configuration')->getCustomOptions($item);
596
+ $label = '';
597
+ foreach($options as $customOption) {
598
+ $label .= $customOption['label'];
599
+ }
600
+ if($label != '') {
601
+ $option_labels[] = array (
602
+ 'name' => 'shipperhq_custom_options',
603
+ 'value' => $label
604
+ );
605
+ return $option_labels;
606
+ }
607
+ return false;
608
+
609
+ }
610
+
611
+
612
+ /**
613
+ * Set up additional attribute array
614
+ * This takes the values from core_config_data
615
+ *
616
+ * Not currently implemented for v1 Magento2.
617
+ *
618
+ * @param $item
619
+ * @return array
620
+ */
621
+ private static function getCustomAttributes($item)
622
+ {
623
+ $rawCustomAttributes = explode(',', Mage::getStoreConfig('carriers/shipper/item_attributes'));
624
+ $customAttributes = array();
625
+ foreach ($rawCustomAttributes as $attribute) {
626
+ $attribute = str_replace(' ', '', $attribute);
627
+ if(!in_array($attribute, self::$_stdAttributeNames) && !in_array($attribute, self::$_legacyAttributeNames) && $attribute != '') {
628
+ $customAttributes[] = $attribute;
629
+ }
630
+ }
631
+
632
+ return self::populateAttributes($customAttributes,$item);
633
+
634
+ }
635
+
636
+ protected static function getSelectedOptions($request)
637
+ {
638
+ $shippingOptions = array();
639
+ if($request->getQuote() && $shippingAddress = $request->getQuote()->getShippingAddress()) {
640
+ foreach(self::$_shippingOptions as $option) {
641
+ //destination type is case sensitive in SHQ
642
+ if(!is_null($shippingAddress->getData($option)) && $shippingAddress->getData($option) != '') {
643
+ $shippingOptions[] = array('name'=> $option, 'value' => strtolower($shippingAddress->getData($option)));
644
+ }
645
+ elseif($option == 'destination_type') {
646
+ $destType = Mage::registry('Shipperhq_Destination_Type');
647
+ if(!is_null($destType) && $destType != '') {
648
+ $shippingOptions[] = array('name'=> 'destination_type', 'value' => strtolower($destType));
649
+ }
650
+ }
651
+ }
652
+ }
653
+
654
+ $selectedOptions = new \ShipperHQ\Shipping\SelectedOptions(
655
+ $shippingOptions
656
+ );
657
+ return $selectedOptions;
658
+
659
+ }
660
+
661
+ /**
662
+ * Gets the magento order number
663
+ * @param $order
664
+ * @return mixed
665
+ */
666
+ protected static function getMagentoOrderNumber($order)
667
+ {
668
+ return $order->getRealOrderId();
669
+
670
+ }
671
+ }
app/code/community/Shipperhq/Shipper/Model/Carrier/Shipper.php ADDED
@@ -0,0 +1,1099 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Shipper shipping model
33
+ *
34
+ * @category ShipperHQ
35
+ * @package ShipperHQ_Shipper
36
+ */
37
+
38
+ include_once 'ShipperHQ/WS/Client/WebServiceClient.php';
39
+ include_once 'ShipperHQ/WS/Response/ErrorMessages.php';
40
+
41
+ class Shipperhq_Shipper_Model_Carrier_Shipper
42
+ extends Mage_Shipping_Model_Carrier_Abstract
43
+ implements Mage_Shipping_Model_Carrier_Interface
44
+ {
45
+
46
+ /**
47
+ * Flag for check carriers for activity
48
+ *
49
+ * @var string
50
+ */
51
+ protected $_activeFlag = 'active';
52
+
53
+ /**
54
+ * Identifies this shipping carrier
55
+ * @var string
56
+ */
57
+ protected $_code = 'shipper';
58
+
59
+ /**
60
+ * Raw rate request data
61
+ *
62
+ * @var Varien_Object|null
63
+ */
64
+ protected $_rawRequest = null;
65
+
66
+ /*
67
+ * Rate request object
68
+ */
69
+ protected $_shipperRequest = null;
70
+
71
+ /**
72
+ * Shipper Web Service instance
73
+ *
74
+ * @var Shipper_Shipper|null
75
+ */
76
+ protected $_shipperWSInstance = null;
77
+
78
+ /**
79
+ * Error Message Lookup Object
80
+ *
81
+ */
82
+ protected $_errorMessageLookup = null;
83
+
84
+ /**
85
+ * Rate result data
86
+ *
87
+ * @var Mage_Shipping_Model_Rate_Result|null
88
+ */
89
+ protected $_result = null;
90
+
91
+ /*
92
+ * Cache of rate results
93
+ */
94
+ protected static $_quotesCache = array();
95
+
96
+ /*
97
+ * Cache setting
98
+ */
99
+ protected $_cacheEnabled;
100
+
101
+
102
+ /**
103
+ * Part of carrier xml config path
104
+ *
105
+ * @var string
106
+ */
107
+ protected $_availabilityConfigField = 'active';
108
+
109
+ /**
110
+ * Code for Wsalogger to pickup
111
+ *
112
+ * @var string
113
+ */
114
+ protected $_modName = 'Shipperhq_Shipper';
115
+
116
+
117
+ /**
118
+ * Retrieve sort order of current carrier
119
+ *
120
+ * @return mixed
121
+ */
122
+ public function getSortOrder()
123
+ {
124
+ $path = 'carriers/'.$this->getId().'/sort_order';
125
+ return Mage::getStoreConfig($path, $this->getStore());
126
+ }
127
+
128
+ /**
129
+ * Collect and get rates
130
+ *
131
+ * @param Mage_Shipping_Model_Rate_Request $request
132
+ * @return Mage_Shipping_Model_Rate_Result|bool|null
133
+ */
134
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
135
+ {
136
+ if (!$this->getConfigFlag($this->_activeFlag)) {
137
+
138
+ return false;
139
+ }
140
+ $initVal = microtime(true);
141
+
142
+ $this->_cacheEnabled = Mage::app()->useCache('collections');
143
+ $this->setRequest($request);
144
+
145
+ $this->_result = $this->_getQuotes();
146
+ $elapsed = microtime(true) - $initVal;
147
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
148
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'Long lapse',$elapsed );
149
+ }
150
+ return $this->getResult();
151
+
152
+ }
153
+
154
+ /**
155
+ * Prepare and set request to this instance
156
+ *
157
+ * @param Mage_Shipping_Model_Rate_Request $request
158
+ * @return Shipperhq_Shipper_Model_Carrier_Shipper
159
+ */
160
+ public function setRequest(Mage_Shipping_Model_Rate_Request $request)
161
+ {
162
+
163
+ if (is_array($request->getAllItems())) {
164
+ $item = current($request->getAllItems());
165
+ if ($item instanceof Mage_Sales_Model_Quote_Item_Abstract) {
166
+ $request->setQuote($item->getQuote());
167
+ }
168
+ }
169
+
170
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Pickup')) {
171
+ Mage::helper('shipperhq_pickup')->addPickupToRequest($request);
172
+ }
173
+
174
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Calendar')) {
175
+ Mage::helper('shipperhq_calendar')->addSelectedDatesToRequest($request);
176
+ }
177
+
178
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Freight')) {
179
+ Mage::helper('shipperhq_freight')->addSelectedFreightOptionsToRequest($request);
180
+ }
181
+
182
+ $isCheckout = Mage::helper('shipperhq_shipper')->isCheckout();
183
+ $cartType = (!is_null($isCheckout) && $isCheckout != 1) ? "CART" : "STD";
184
+ if(Mage::helper('shipperhq_shipper')->isMultiAddressCheckout()) {
185
+ $cartType = 'MAC';
186
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Pickup')&&
187
+ Mage::helper('shipperhq_pickup')->pickupPreselected($request)) {
188
+ $cartType = 'MAC_PICKUP';
189
+ }
190
+ }
191
+ $request->setCartType($cartType);
192
+ $request->setStore($this->getStore());
193
+ $this->_shipperRequest = Mage::getSingleton('Shipperhq_Shipper_Model_Carrier_Convert_ShipperMapper')->
194
+ getShipperTranslation($request);
195
+ $this->_rawRequest = $request;
196
+ return $this;
197
+
198
+ }
199
+
200
+ /**
201
+ * Get result of request
202
+ *
203
+ * @return mixed
204
+ */
205
+ public function getResult()
206
+ {
207
+ return $this->_result;
208
+ }
209
+
210
+
211
+ public function refreshCarriers()
212
+ {
213
+ $allowedMethods = $this->getAllowedMethods();
214
+ if(count($allowedMethods) == 0 ) {
215
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
216
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'refresh carriers',
217
+ 'Allowed methods web service did not contain any shipping methods for carriers');
218
+ }
219
+ $result['result'] = false;
220
+ $result['error'] = 'ShipperHQ Error: No shipping methods for carrier setup in your ShipperHQ account';
221
+ return $result;
222
+ }
223
+ return $allowedMethods;
224
+
225
+ }
226
+
227
+ /**
228
+ * Get allowed shipping methods
229
+ *
230
+ * @return array
231
+ */
232
+ public function getAllowedMethods()
233
+ {
234
+ $ourCarrierCode = $this->getId();
235
+ $result = array();
236
+ $allowedMethods = array();
237
+ $allowedMethodUrl = Mage::helper('shipperhq_shipper')->getAllowedMethodGatewayUrl();
238
+ $timeout = Mage::helper('shipperhq_shipper')->getWebserviceTimeout();
239
+ $shipperMapper = Mage::getSingleton('Shipperhq_Shipper_Model_Carrier_Convert_ShipperMapper');
240
+ $resultSet = $this->_getShipperInstance()->sendAndReceive(
241
+ $shipperMapper->getCredentialsTranslation(), $allowedMethodUrl, $timeout);
242
+
243
+ $allowedMethodResponse = $resultSet['result'];
244
+
245
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
246
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'Allowed methods response:',
247
+ $resultSet['debug']);
248
+ }
249
+ if (!is_object($allowedMethodResponse)) {
250
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
251
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper',
252
+ 'Allowed Methods: No or invalid response received from Shipper HQ',
253
+ $allowedMethodResponse);
254
+ }
255
+
256
+ $shipperHQ = "<a href=https://shipperhq.com/ratesmgr/websites>ShipperHQ</a> ";
257
+ $result['result'] = false;
258
+ $result['error'] = 'ShipperHQ is not contactable, verify the details from the website configuration in ' .$shipperHQ;
259
+ return $result;
260
+ }
261
+ else if (count($allowedMethodResponse->errors)){
262
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
263
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Allowed methods: response contained following errors',
264
+ $allowedMethodResponse);
265
+
266
+ }
267
+ $error = 'ShipperHQ Error: ';
268
+ foreach($allowedMethodResponse->errors as $anError) {
269
+ if(isset($anError->internalErrorMessage)) {
270
+ $error .= ' ' .$anError->internalErrorMessage;
271
+ }
272
+ elseif(isset($anError->externalErrorMessage) && $anError->externalErrorMessage != '') {
273
+ $error .= ' ' .$anError->externalErrorMessage;
274
+ }
275
+ }
276
+ $result['result'] = false;
277
+ $result['error'] = $error;
278
+ return $result;
279
+ }
280
+ else if ( !count($allowedMethodResponse->carrierMethods)) {
281
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
282
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper',
283
+ 'Allowed methods web service did not return any carriers or shipping methods',
284
+ $allowedMethodResponse);
285
+ }
286
+ $result['result'] = false;
287
+ $result['warning'] = 'ShipperHQ Warning: No carriers setup, log in to ShipperHQ Dashboard and create carriers';
288
+ return $result;
289
+ }
290
+
291
+ $returnedMethods = $allowedMethodResponse->carrierMethods;
292
+
293
+ $carrierConfig = array();
294
+
295
+ foreach ($returnedMethods as $carrierMethod) {
296
+
297
+ $rateMethods = $carrierMethod->methods;
298
+
299
+ foreach ($rateMethods as $method) {
300
+ if(!is_null($ourCarrierCode) && $carrierMethod->carrierCode != $ourCarrierCode) {
301
+ continue;
302
+ }
303
+
304
+ $allowedMethodCode = /*$carrierMethod->carrierCode . '_' .*/ $method->methodCode;
305
+ $allowedMethodCode = preg_replace('/&|;| /', "_", $allowedMethodCode);
306
+
307
+ if (!array_key_exists($allowedMethodCode, $allowedMethods)) {
308
+ $allowedMethods[$allowedMethodCode] = $carrierMethod->title . '(' . $method->name . ')';
309
+ }
310
+ }
311
+
312
+ $carrierConfig[$carrierMethod->carrierCode]['title'] = $carrierMethod->title;
313
+ if(isset($carrierMethod->sortOrder)) {
314
+ $carrierConfig[$carrierMethod->carrierCode]['sortOrder'] = $carrierMethod->sortOrder;
315
+ }
316
+ }
317
+
318
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
319
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'Allowed methods parsed result: ', $allowedMethods);
320
+ }
321
+ // go set carrier titles
322
+ $this->setCarrierConfig($carrierConfig);
323
+
324
+ return $allowedMethods;
325
+ }
326
+
327
+ public function createMergedRate($ratesToAdd)
328
+ {
329
+ $result = Mage::getModel('shipping/rate_result');
330
+ foreach ($ratesToAdd as $rateToAdd) {
331
+ $method = Mage::getModel('shipping/rate_result_method');
332
+ $method->setPrice((float)$rateToAdd['price']);
333
+ $method->setCost((float)$rateToAdd['price']);
334
+ $method->setCarrier($this->_code);
335
+ $method->setCarrierTitle($rateToAdd['mergedTitle']);
336
+ $method->setMethod($rateToAdd['title']);
337
+ $method->setMethodTitle($rateToAdd['mergedDescription']);
338
+ $method->setFreightQuoteId($rateToAdd['freight_quote_id']);
339
+ $method->setMethodDescription($rateToAdd['mergedDescription']);
340
+ $method->setCarrierType(Mage::helper('shipperhq_shipper')->__('multiple_shipments'));
341
+ // $method->setExpectedDelivery($rateToAdd['expected_delivery']);
342
+ // $method->setDispatchDate($rateToAdd['dispatch_date']);
343
+ $result->append($method);
344
+ }
345
+ return $result;
346
+ }
347
+
348
+ public function extractShipperhqRates($carrierRate, $carrierGroupId, $carrierGroupDetail, $isSplit)
349
+ {
350
+
351
+ $carrierResultWithRates = array(
352
+ 'code' => $carrierRate->carrierCode,
353
+ 'title' => $carrierRate->carrierTitle);
354
+
355
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Calendar')) {
356
+ Mage::helper('shipperhq_calendar')->cleanUpCalendarsInSession($carrierRate->carrierCode, $carrierGroupId);
357
+ }
358
+ if(isset($carrierRate->error)) {
359
+ $carrierResultWithRates['error'] = (array)$carrierRate->error;
360
+ $carrierResultWithRates['carriergroup_detail']['carrierGroupId'] = $carrierGroupId;
361
+ }
362
+
363
+ if(isset($carrierRate->rates) && !array_key_exists('error', $carrierResultWithRates)) {
364
+ $thisCarriersRates = $this->populateRates($carrierRate, $carrierGroupDetail, $carrierGroupId, true);
365
+ $carrierResultWithRates['rates'] = $thisCarriersRates;
366
+ }
367
+
368
+ return $carrierResultWithRates;
369
+ }
370
+
371
+ protected function populateRates($carrierRate, &$carrierGroupDetail, $carrierGroupId)
372
+ {
373
+ $thisCarriersRates = array();
374
+ $hideNotify = Mage::getStoreConfig('carriers/shipper/hide_notify');
375
+ $locale = $this->getLocaleInGlobals();
376
+ $dateOption = $carrierRate->dateOption;
377
+ $deliveryMessage = isset($carrierRate->deliveryDateMessage) ?
378
+ Mage::helper('shipperhq_shipper')->__($carrierRate->deliveryDateMessage) : '';
379
+ if(is_null($deliveryMessage) || $deliveryMessage == '') {
380
+ $deliveryMessage = $dateOption == Shipperhq_Shipper_Helper_Data::TIME_IN_TRANSIT ? 'business day(s)' :
381
+ Mage::helper('shipperhq_shipper')->__('Delivers :');
382
+ }
383
+ $customDescription = isset($carrierRate->customDescription) ?
384
+ Mage::helper('shipperhq_shipper')->__($carrierRate->customDescription) : false;
385
+ $freightRate = isset($carrierRate->availableOptions) && !empty($carrierRate->availableOptions);
386
+ $baseRate = 1;
387
+ $baseCurrencyCode = Mage::app()->getStore()->getBaseCurrency()->getCode();
388
+ $dateFormat = isset($carrierRate->deliveryDateFormat) ?
389
+ $this->getCldrDateFormat($locale, $carrierRate->deliveryDateFormat) : Mage::helper('shipperhq_shipper')->getDateFormat();
390
+
391
+ foreach($carrierRate->rates as $oneRate) {
392
+ $methodDescription = false;
393
+ $title = Mage::helper('shipperhq_shipper')->isTransactionIdEnabled() ?
394
+ Mage::helper('shipperhq_shipper')->__($oneRate->name).' (' .$carrierGroupDetail['transaction'] .')'
395
+ : Mage::helper('shipperhq_shipper')->__($oneRate->name);
396
+ //currency conversion required
397
+ if(isset($oneRate->currency)) {
398
+ if($oneRate->currency != $baseCurrencyCode || $baseRate != 1) {
399
+ $baseRate = Mage::helper('shipperhq_shipper')->getBaseCurrencyRate($oneRate->currency);
400
+ if(!$baseRate) {
401
+ $carrierResultWithRates['error'] = Mage::helper('directory')
402
+ ->__('Can\'t convert rate from "%s".',
403
+ $oneRate->currency);
404
+ $carrierResultWithRates['carriergroup_detail']['carrierGroupId'] = $carrierGroupId;
405
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
406
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Shipper', 'Currency rate missing ',
407
+ 'Currency code in shipping rate is ' .$oneRate->currency
408
+ .' but there is no currency conversion rate configured so we cannot display this shipping rate');
409
+ }
410
+ continue;
411
+ }
412
+
413
+ }
414
+ }
415
+ Mage::helper('shipperhq_shipper')->populateRateLevelDetails((array)$oneRate, $carrierGroupDetail, $baseRate);
416
+ if($oneRate->deliveryDate && is_numeric($oneRate->deliveryDate)) {
417
+ $deliveryDate = Mage::app()->getLocale()->date($oneRate->deliveryDate/1000, null, null, true)->toString($dateFormat);
418
+ if($dateOption == Shipperhq_Shipper_Helper_Data::DELIVERY_DATE_OPTION && isset($oneRate->deliveryDate)) {
419
+ $methodDescription = Mage::helper('shipperhq_shipper')->__(' %s %s',$deliveryMessage, $deliveryDate);
420
+ if($oneRate->latestDeliveryDate && is_numeric($oneRate->latestDeliveryDate)) {
421
+ $latestDeliveryDate = Mage::app()->getLocale()->date($oneRate->latestDeliveryDate/1000, null, null, true)->toString($dateFormat);
422
+ $methodDescription.= ' - ' .$latestDeliveryDate;
423
+ }
424
+ }
425
+ else if($dateOption == Shipperhq_Shipper_Helper_Data::TIME_IN_TRANSIT
426
+ && isset($oneRate->dispatchDate)) {
427
+ $deliveryMessage = Mage::helper('shipperhq_shipper')->__('business days');
428
+ $numDays = floor(abs($oneRate->deliveryDate/1000 - $oneRate->dispatchDate/1000)/60/60/24);
429
+ if($oneRate->latestDeliveryDate && is_numeric($oneRate->latestDeliveryDate)) {
430
+ $maxNumDays = floor(abs($oneRate->latestDeliveryDate/1000 - $oneRate->dispatchDate/1000)/60/60/24);
431
+ $methodDescription = Mage::helper('shipperhq_shipper')->__(' (%s - %s %s)',$numDays, $maxNumDays, $deliveryMessage);
432
+ }
433
+ else {
434
+ $methodDescription = Mage::helper('shipperhq_shipper')->__(' (%s %s)',$numDays, $deliveryMessage);
435
+ }
436
+ }
437
+ }
438
+ if($oneRate->dispatchDate && is_numeric($oneRate->dispatchDate)) {
439
+ $dispatchDate = Mage::app()->getLocale()->date($oneRate->dispatchDate/1000, null, null, true)->toString($dateFormat);
440
+ }
441
+
442
+ if($methodDescription) {
443
+ $title.= ' ' .$methodDescription;
444
+ }
445
+ if($carrierRate->carrierType == 'shqshared') {
446
+ $carrierType = $carrierRate->carrierType .'_' .$oneRate->carrierType;
447
+ }
448
+ else {
449
+ $carrierType = $oneRate->carrierType;
450
+ }
451
+ $rateToAdd = array(
452
+ 'method_code' => $oneRate->code,
453
+ 'method_title' => $title,
454
+ 'cost' => (float)$oneRate->shippingPrice * $baseRate,
455
+ 'price' => (float)$oneRate->totalCharges * $baseRate,
456
+ 'carrier_type' => $carrierType,
457
+ 'carrier_id' => $carrierRate->carrierId,
458
+ 'freight_rate' => $freightRate
459
+ );
460
+
461
+ if($oneRate->customDuties) {
462
+ $rateToAdd['custom_duties'] = $oneRate->customDuties;
463
+ }
464
+
465
+ if($oneRate->deliveryDate && is_numeric($oneRate->deliveryDate)) {
466
+ $carrierGroupDetail['delivery_date'] = $deliveryDate;
467
+ $rateToAdd['delivery_date'] = $deliveryDate;
468
+ $carrierGroupDetail['dateFormat'] = $dateFormat;
469
+ }
470
+
471
+ if($oneRate->dispatchDate && is_numeric($oneRate->dispatchDate)) {
472
+ $carrierGroupDetail['dispatch_date'] = $dispatchDate;
473
+ $rateToAdd['dispatch_date'] = $dispatchDate;
474
+ }
475
+ if($methodDescription) {
476
+ $rateToAdd['method_description'] = $methodDescription;
477
+ }
478
+ $rateToAdd['carriergroup_detail'] = $carrierGroupDetail;
479
+
480
+ if(!$hideNotify && isset($carrierRate->notices)) {
481
+ foreach($carrierRate->notices as $notice) {
482
+ if(array_key_exists('carrier_notice', $rateToAdd)) {
483
+ $rateToAdd['carrier_notice'] .= ' ' .(string)$notice ;
484
+ } else {
485
+ $rateToAdd['carrier_notice'] = (string)$notice ;
486
+ }
487
+ }
488
+ }
489
+
490
+ if($customDescription) {
491
+ $rateToAdd['custom_description'] = $customDescription;
492
+ }
493
+
494
+ $thisCarriersRates[] = $rateToAdd;
495
+ }
496
+ return $thisCarriersRates;
497
+ }
498
+
499
+ protected function getLocaleInGlobals()
500
+ {
501
+ $globals = Mage::helper('shipperhq_shipper')->getQuoteStorage()->getShipperGlobal();
502
+ if(isset($globals['preferredLocale'])) {
503
+ return $globals['preferredLocale'];
504
+ }
505
+ return 'en-US';
506
+ }
507
+
508
+ /**
509
+ * Get configuration data of carrier
510
+ *
511
+ * @param string $type
512
+ * @param string $code
513
+ * @return array|bool
514
+ */
515
+ public function getCode($type, $code = '')
516
+ {
517
+ $codes = array(
518
+ 'date_format' =>array(
519
+ 'dd-mm-yyyy' => 'd-m-Y',
520
+ 'mm/dd/yyyy' => 'm/d/Y',
521
+ 'EEE dd-MM-yyyy' => 'D d-m-Y'
522
+ ),
523
+ 'short_date_format' =>array(
524
+ 'dd-mm-yyyy' => 'd-m-Y',
525
+ 'mm/dd/yyyy' => 'm/d/Y',
526
+ 'EEE dd-MM-yyyy' => 'D d-m-Y'
527
+ ),
528
+ 'datepicker_format' => array(
529
+ 'dd-mm-yyyy' => 'dd-mm-yy',
530
+ 'mm/dd/yyyy' => 'mm/dd/yy',
531
+ 'EEE dd-MM-yyyy' => 'DD d-MM-yy'
532
+
533
+ ),
534
+ 'zend_date_format' => array(
535
+ 'dd-mm-yyyy' => 'dd-MM-y',
536
+ 'mm/dd/yyyy' => 'MM/dd/y',
537
+ 'EEE dd-MM-yyyy' => 'E d-M-y'
538
+ ),
539
+ 'cldr_date_format' => array(
540
+ 'en-US' => array(
541
+ 'yMd' => 'MM/dd/Y',
542
+ 'yMMMd' => 'MMM d, Y',
543
+ 'yMMMEd' => 'EEE, MMM d, Y',
544
+ 'yMEd' => 'EEE, M/d/Y',
545
+ 'MMMd' => 'MMM d',
546
+ 'MMMEd' => 'EEE, MMM d',
547
+ 'MEd' => 'EEE, M/d',
548
+ 'Md' => 'M/d',
549
+ 'yM' => 'M/Y',
550
+ 'yMMM' => 'MMM Y',
551
+ 'MMM' => 'MMM',
552
+ 'E' => 'EEE',
553
+ 'Ed' => 'd EEE',
554
+ ),
555
+ 'en-GB' => array(
556
+ 'yMd' => 'dd/MM/Y',
557
+ 'yMMMd' => 'd MMM Y',
558
+ 'yMMMEd' => 'EEE, d MMM Y',
559
+ 'yMEd' => 'EEE, d/M/Y',
560
+ 'MMMd' => 'd MMM',
561
+ 'MMMEd' => 'EEE, d MMM',
562
+ 'MEd' => 'EEE, d/M',
563
+ 'Md' => 'd/M',
564
+ 'yM' => 'M/Y',
565
+ 'yMMM' => 'MMM Y',
566
+ 'MMM' => 'MMM',
567
+ 'E' => 'EEE',
568
+ 'Ed' => 'EEE d',
569
+ )
570
+ )
571
+
572
+
573
+
574
+ );
575
+ $codes['error'] = $this->_getErrorMessageLookup()->getErrors();
576
+
577
+ if (!isset($codes[$type])) {
578
+ return false;
579
+ } elseif ('' === $code) {
580
+ return $codes[$type];
581
+ }
582
+
583
+ if (!isset($codes[$type][$code])) {
584
+ return false;
585
+ } else {
586
+ return $codes[$type][$code];
587
+ }
588
+ }
589
+
590
+ protected function getCldrDateFormat($locale, $code)
591
+ {
592
+ $dateFormatArray = $this->getCode('cldr_date_format', $locale);
593
+ $dateFormat = is_array($dateFormatArray) && array_key_exists($code, $dateFormatArray) ? $dateFormatArray[$code]:
594
+ Mage::helper('shipperhq_shipper')->getDateFormat();
595
+ return $dateFormat;
596
+ }
597
+
598
+ /**
599
+ * Do remote request for and handle errors
600
+ *
601
+ * @return Mage_Shipping_Model_Rate_Result
602
+ */
603
+ protected function _getQuotes()
604
+ {
605
+ $requestString = serialize($this->_shipperRequest);
606
+ $resultSet = $this->_getCachedQuotes($requestString);
607
+ $timeout = Mage::helper('shipperhq_shipper')->getWebserviceTimeout();
608
+ if (!$resultSet) {
609
+ $initVal = microtime(true);
610
+ $resultSet = $this->_getShipperInstance()->sendAndReceive($this->_shipperRequest,
611
+ Mage::helper('shipperhq_shipper')->getRateGatewayUrl(), $timeout);
612
+ $elapsed = microtime(true) - $initVal;
613
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
614
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'Short lapse',$elapsed );
615
+ }
616
+ if(!$resultSet['result']){
617
+ $backupRates = $this->_getBackupCarrierRates();
618
+ if ($backupRates) {
619
+ return $backupRates;
620
+ }
621
+ }
622
+ if(is_object($resultSet['result'])) {
623
+ $this->_setCachedQuotes($requestString, $resultSet);
624
+ }
625
+ }
626
+
627
+ /**
628
+ *
629
+ * This holds the raw json
630
+ */
631
+ /**
632
+ * if (Mage::helper('shipperhq_shipper')->isDebug()) {
633
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Request/Response',
634
+ $resultSet);
635
+ }
636
+ **/
637
+ return $this->_parseShipperResponse($resultSet['result']);
638
+
639
+ }
640
+
641
+
642
+ /**
643
+ * @param $shipperResponse
644
+ * @return Mage_Shipping_Model_Rate_Result
645
+ */
646
+ protected function _parseShipperResponse($shipperResponse)
647
+ {
648
+ $debugRequest = $this->_shipperRequest;
649
+
650
+
651
+ $debugRequest->credentials = null;
652
+ $debugData = array('request' => $debugRequest, 'response' => $shipperResponse);
653
+
654
+ //first check and save globals for display purposes
655
+ if(is_object($shipperResponse) && isset($shipperResponse->globalSettings)) {
656
+ $globals = (array)$shipperResponse->globalSettings;
657
+ Mage::helper('shipperhq_shipper')->getQuoteStorage()->setShipperGlobal($globals);
658
+ }
659
+
660
+ if(Mage::helper('shipperhq_shipper')->isSortOnPrice()) {
661
+ $result = Mage::getModel('shipping/rate_result');
662
+ }
663
+ else {
664
+ $result = Mage::getModel('shipperhq_shipper/rate_result');
665
+ }
666
+ // If no rates are found return error message
667
+ if (!is_object($shipperResponse)) {
668
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
669
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Shipper HQ did not return a response',
670
+ $debugData);
671
+ }
672
+ $message = $this->getCode('error', 1550);
673
+
674
+ return $this->returnGeneralError($message);
675
+ }
676
+ elseif(!empty($shipperResponse->errors)) {
677
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
678
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Shipper HQ returned an error',
679
+ $debugData);
680
+ }
681
+ if(isset($shipperResponse->errors)) {
682
+ foreach($shipperResponse->errors as $error) {
683
+ $this->appendError($result, $error, $this->_code, $this->getConfigData('title'));
684
+ }
685
+ }
686
+ return $result;
687
+ }
688
+ elseif(!isset($shipperResponse->carrierGroups)) {
689
+
690
+ }
691
+
692
+ if(isset($shipperResponse->carrierGroups)) {
693
+ if(count($shipperResponse->carrierGroups) > 1 && !isset($shipperResponse->mergedRateResponse )) {
694
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
695
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper',
696
+ 'Shipper HQ returned multi origin/group rates without any merged rate details',$debugData);
697
+ }
698
+ }
699
+ $carrierRates = $this->_processRatesResponse($shipperResponse);
700
+ }
701
+ else {
702
+ $carrierRates = array();
703
+ }
704
+ if(count($carrierRates) == 0) {
705
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
706
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Shipper HQ did not return any carrier rates',$debugData);
707
+ }
708
+ return $result;
709
+ }
710
+
711
+ foreach ($carrierRates as $carrierRate) {
712
+ if (isset($carrierRate['error'])) {
713
+ $carriergroupId = null;
714
+ $carrierGroupDetail = null;
715
+ if(array_key_exists('carriergroup_detail', $carrierRate)
716
+ && !is_null($carrierRate['carriergroup_detail'])) {
717
+ if(array_key_exists('carrierGroupId', $carrierRate['carriergroup_detail'])) {
718
+ $carriergroupId = $carrierRate['carriergroup_detail']['carrierGroupId'];
719
+ }
720
+ $carrierGroupDetail = $carrierRate['carriergroup_detail'];
721
+ }
722
+ $this->appendError($result, $carrierRate['error'], $carrierRate['code'], $carrierRate['title'],
723
+ $carriergroupId,$carrierGroupDetail);
724
+ continue;
725
+ }
726
+
727
+ if (!array_key_exists('rates', $carrierRate)) {
728
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
729
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper',
730
+ 'Shipper HQ did not return any rates for '. $carrierRate['code'] .' ' .$carrierRate['title']
731
+ ,$debugData);
732
+ }
733
+ } else {
734
+
735
+ foreach ($carrierRate['rates'] as $rateDetails) {
736
+ $rate = Mage::getModel('shipping/rate_result_method');
737
+ $rate->setCarrier($carrierRate['code']);
738
+ $rate->setCarrierTitle($carrierRate['title']);
739
+ $methodCombineCode = preg_replace('/&|;| /', "_", $rateDetails['method_code']);
740
+ $rate->setMethod($methodCombineCode);
741
+ $rate->setMethodTitle(Mage::helper('shipperhq_shipper')->__($rateDetails['method_title']));
742
+ if(array_key_exists('method_description', $rateDetails)) {
743
+ $rate->setMethodDescription(Mage::helper('shipperhq_shipper')->__($rateDetails['method_description']));
744
+ }
745
+ $rate->setCost($rateDetails['cost']);
746
+ $rate->setPrice($rateDetails['price']);
747
+ if(array_key_exists('custom_duties', $rateDetails)) {
748
+ $rate->setCustomDuties($rateDetails['custom_duties']);
749
+ }
750
+
751
+ if(array_key_exists('carrier_type', $rateDetails)) {
752
+ $rate->setCarrierType($rateDetails['carrier_type']);
753
+ }
754
+
755
+ if(array_key_exists('carrier_id', $rateDetails)) {
756
+ $rate->setCarrierId($rateDetails['carrier_id']);
757
+ }
758
+
759
+ if(array_key_exists('dispatch_date', $rateDetails)) {
760
+ $rate->setDispatchDate($rateDetails['dispatch_date']);
761
+ }
762
+
763
+ if(array_key_exists('delivery_date', $rateDetails)) {
764
+ $rate->setDeliveryDate($rateDetails['delivery_date']);
765
+ }
766
+
767
+ if(array_key_exists('carriergroup_detail', $rateDetails)
768
+ && !is_null($rateDetails['carriergroup_detail'])) {
769
+ $rate->setCarriergroupShippingDetails(
770
+ Mage::helper('shipperhq_shipper')->encodeShippingDetails($rateDetails['carriergroup_detail']));
771
+ if(array_key_exists('carrierGroupId', $rateDetails['carriergroup_detail'])) {
772
+ $rate->setCarriergroupId($rateDetails['carriergroup_detail']['carrierGroupId']);
773
+ }
774
+ if(array_key_exists('checkoutDescription', $rateDetails['carriergroup_detail'])) {
775
+ $rate->setCarriergroup($rateDetails['carriergroup_detail']['checkoutDescription']);
776
+ }
777
+ }
778
+
779
+ if(array_key_exists('carrier_notice', $rateDetails)) {
780
+ $rate->setCarrierNotice($rateDetails['carrier_notice']);
781
+ }
782
+
783
+ if(array_key_exists('freight_rate', $rateDetails)) {
784
+ $rate->setFreightRate($rateDetails['freight_rate']);
785
+ }
786
+
787
+ if(array_key_exists('custom_description', $rateDetails)) {
788
+ $rate->setCustomDescription($rateDetails['custom_description']);
789
+ }
790
+
791
+ $result->append($rate);
792
+ }
793
+ }
794
+ }
795
+
796
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
797
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'Rate request and result', $debugData);
798
+ }
799
+ return $result;
800
+
801
+ }
802
+
803
+ /*
804
+ *
805
+ * Build array of rates based on split or merged rates display
806
+ */
807
+ protected function _processRatesResponse($shipperResponse)
808
+ {
809
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Freight')) {
810
+ Mage::helper('shipperhq_freight')->parseFreightDetails($shipperResponse, $this->getQuote()->getShippingAddress()->getIsCheckout());
811
+ }
812
+
813
+ //Use multi-origin/group processing
814
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Splitrates')
815
+ && isset($shipperResponse->mergedRateResponse) && count($shipperResponse->carrierGroups) > 1) {
816
+ return Mage::helper('shipperhq_splitrates')->parseCarrierGroupRates($shipperResponse, $this->_rawRequest);
817
+ }
818
+
819
+ Mage::helper('shipperhq_shipper')->setStandardShipperResponseType();
820
+
821
+ $carrierGroups = $shipperResponse->carrierGroups;
822
+ $ratesArray = array();
823
+ $globals = (array)$shipperResponse->globalSettings;
824
+ $responseSummary = (array)$shipperResponse->responseSummary;
825
+ foreach($carrierGroups as $carrierGroup)
826
+ {
827
+ $carrierGroupDetail = (array)$carrierGroup->carrierGroupDetail;
828
+ $carriergroupId = array_key_exists('carrierGroupId', $carrierGroupDetail) ? $carrierGroupDetail['carrierGroupId'] : 0;
829
+
830
+ Mage::unregister('shipperhq_transaction');
831
+ Mage::register('shipperhq_transaction', $responseSummary['transactionId']);
832
+ $carrierGroupDetail['transaction'] = $responseSummary['transactionId'];
833
+
834
+ $this->_setCarriergroupOnItems($carrierGroupDetail, $carrierGroup->products);
835
+ $globals = array_merge($globals,$carrierGroupDetail);
836
+ //Pass off each carrier group to helper to decide best fit to process it.
837
+ //Push result back into our array
838
+ foreach($carrierGroup->carrierRates as $carrierRate) {
839
+ $carrierResultWithRates = Mage::helper('shipperhq_shipper')->chooseCarrierAndProcess($carrierRate, $carriergroupId, $carrierGroupDetail, false);
840
+ $ratesArray[] = $carrierResultWithRates;
841
+ }
842
+ }
843
+ Mage::helper('shipperhq_shipper')->getQuoteStorage()->setShipperGlobal($globals);
844
+
845
+ $carriergroupDescriber = $shipperResponse->globalSettings->carrierGroupDescription;
846
+ if($carriergroupDescriber != '') {
847
+ Mage::helper('shipperhq_shipper')->saveConfig(Shipperhq_Shipper_Helper_Data::SHIPPERHQ_SHIPPER_CARRIERGROUP_DESC_PATH,
848
+ $carriergroupDescriber);
849
+ }
850
+
851
+ Mage::helper('shipperhq_shipper')->refreshConfig();
852
+
853
+ return $ratesArray;
854
+ }
855
+
856
+ protected function _setCarriergroupOnItems($carriergroupDetails, $productInRateResponse)
857
+ {
858
+ $quoteItems = $this->getQuote()->getAllItems();
859
+ foreach($productInRateResponse as $item) {
860
+ $item = (array)$item;
861
+ $sku = $item['sku'];
862
+ $itemId = array_key_exists('id', $item) ? $item['id'] : false;
863
+ foreach($quoteItems as $item)
864
+ {
865
+ if($item->getSku() == $sku && (!$itemId || $item->getId() == $itemId)) {
866
+ $item->setCarriergroupId($carriergroupDetails['carrierGroupId']);
867
+ $item->setCarriergroup($carriergroupDetails['name']);
868
+ if($parentItem = $item->getParentItem()) {
869
+ $parentItem->setCarriergroupId($carriergroupDetails['carrierGroupId']);
870
+ $parentItem->setCarriergroup($carriergroupDetails['name']);
871
+
872
+ }
873
+ }
874
+ }
875
+
876
+ foreach($this->_rawRequest->getAllItems() as $quoteItem)
877
+ {
878
+ if($quoteItem->getSku() == $sku && (!$itemId || $quoteItem->getQuoteItemId() == $itemId)) {
879
+ $quoteItem->setCarriergroupId($carriergroupDetails['carrierGroupId']);
880
+ $quoteItem->setCarriergroup($carriergroupDetails['name']);
881
+ if($parentItem = $quoteItem->getParentItem()) {
882
+ $parentItem->setCarriergroupId($carriergroupDetails['carrierGroupId']);
883
+ $parentItem->setCarriergroup($carriergroupDetails['name']);
884
+ }
885
+ }
886
+ }
887
+ }
888
+ }
889
+
890
+ /**
891
+ * Retrieve checkout quote model object
892
+ *
893
+ * @return Mage_Sales_Model_Quote
894
+ */
895
+ public function getQuote()
896
+ {
897
+ return Mage::helper('shipperhq_shipper')->getQuote();
898
+ }
899
+
900
+ /**
901
+ *
902
+ * Build up an error message when no carrier rates returned
903
+ * @return Mage_Shipping_Model_Rate_Result
904
+ */
905
+ protected function returnGeneralError($message = null)
906
+ {
907
+ $result = Mage::getModel('shipping/rate_result');
908
+ $error = Mage::getModel('shipping/rate_result_error');
909
+ $error->setCarrier($this->_code);
910
+ $error->setCarrierTitle($this->getConfigData('title'));
911
+ $error->setCarriergroupId('');
912
+ if($message && Mage::helper('shipperhq_shipper')->isDebug()) {
913
+ $error->setErrorMessage($message);
914
+ }
915
+ else {
916
+ $error->setErrorMessage($this->getConfigData('specificerrmsg'));
917
+ }
918
+ $result->append($error);
919
+ return $result;
920
+ }
921
+
922
+ /**
923
+ *
924
+ * Generate error message from ShipperHQ response.
925
+ * Display of error messages per carrier is managed in SHQ configuration
926
+ *
927
+ * @param $result
928
+ * @param $errorDetails
929
+ * @return Mage_Shipping_Model_Rate_Result
930
+ */
931
+ protected function appendError($result, $errorDetails, $carrierCode, $carrierTitle, $carrierGroupId = null, $carrierGroupDetail = null)
932
+ {
933
+ if(is_object($errorDetails)) {
934
+ $errorDetails = get_object_vars($errorDetails);
935
+ }
936
+ if ((array_key_exists('internalErrorMessage', $errorDetails) && $errorDetails['internalErrorMessage'] != '')
937
+ || (array_key_exists('externalErrorMessage', $errorDetails) && $errorDetails['externalErrorMessage'] != ''))
938
+ {
939
+ $errorMessage = false;
940
+ if (Mage::helper('wsalogger')->isDebugError() && array_key_exists('internalErrorMessage', $errorDetails)
941
+ && $errorDetails['internalErrorMessage'] != '') {
942
+ $errorMessage = $errorDetails['internalErrorMessage'];
943
+ }
944
+ else if(array_key_exists('externalErrorMessage', $errorDetails)
945
+ && $errorDetails['externalErrorMessage'] != '') {
946
+ $errorMessage = $errorDetails['externalErrorMessage'];
947
+ }
948
+ if($errorMessage) {
949
+ $error = Mage::getModel('shipping/rate_result_error');
950
+ $error->setCarrier($carrierCode);
951
+ $error->setCarrierTitle($carrierTitle);
952
+ $error->setErrorMessage(Mage::helper('shipperhq_shipper')->__($errorMessage));
953
+ if(!is_null($carrierGroupId)) {
954
+ $error->setCarriergroupId($carrierGroupId);
955
+ }
956
+ if(is_array($carrierGroupDetail) && array_key_exists('checkoutDescription', $carrierGroupDetail)) {
957
+ $error->setCarriergroup($carrierGroupDetail['checkoutDescription']);
958
+ }
959
+
960
+ $result->append($error);
961
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
962
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Shipper HQ returned error', $errorDetails);
963
+ }
964
+ }
965
+
966
+ }
967
+ return $result;
968
+ }
969
+
970
+ /*
971
+ * This dynamically updates the carrier titles from ShipperHQ
972
+ * Is required as don't want to set these on every quote request
973
+ */
974
+ protected function setCarrierConfig($carrierConfig)
975
+ {
976
+ foreach ($carrierConfig as $carrierCode=>$config) {
977
+ Mage::helper('shipperhq_shipper')->saveCarrierTitle($carrierCode, $config['title']);
978
+ if(array_key_exists('sortOrder', $config)) {
979
+ Mage::helper('shipperhq_shipper')->saveConfig('carriers/'.$carrierCode.'/sort_order', $config['sortOrder']);
980
+ }
981
+ }
982
+
983
+ }
984
+
985
+ protected function _getBackupCarrierRates()
986
+ {
987
+ $backupHandler = Mage::getModel('shipperhq_shipper/carrier_backup');
988
+ return $backupHandler->getBackupCarrierRates($this->_rawRequest);
989
+ }
990
+
991
+ /**
992
+ * Initialise shipper library class
993
+ *
994
+ * @return null|Shipper_Shipper
995
+ */
996
+ protected function _getShipperInstance()
997
+ {
998
+ if (empty($this->_shipperWSInstance)) {
999
+ $this->_shipperWSInstance = new \ShipperHQ\WS\Client\WebServiceClient();
1000
+ }
1001
+ return $this->_shipperWSInstance;
1002
+ }
1003
+
1004
+ /**
1005
+ * Initialise shipper library class
1006
+ *
1007
+ * @return null|Shipper_Shipper
1008
+ */
1009
+ protected function _getErrorMessageLookup()
1010
+ {
1011
+ if (empty($this->_errorMessageLookup)) {
1012
+ $this->_errorMessageLookup = new \ShipperHQ\WS\Response\ErrorMessages();
1013
+ }
1014
+ return $this->_errorMessageLookup;
1015
+ }
1016
+
1017
+ /**
1018
+ * Returns cache key for some request to carrier quotes service
1019
+ *
1020
+ * @param string|array $requestParams
1021
+ * @return string
1022
+ */
1023
+ protected function _getQuotesCacheKey($requestParams)
1024
+ {
1025
+
1026
+ if (is_array($requestParams)) {
1027
+ $requestParams = implode(',', array_merge(
1028
+ array($this->getCarrierCode()),
1029
+ array_keys($requestParams),
1030
+ $requestParams)
1031
+ );
1032
+
1033
+ }
1034
+ else {
1035
+ $unSerialized = unserialize($requestParams);
1036
+ if(isset($unSerialized->cart)) {
1037
+ $cart = $unSerialized->cart;
1038
+ $cartItems = $cart['items'];
1039
+ foreach($cartItems as $key => $cartItem) {
1040
+ $cartItem['id'] = '';
1041
+ $cartItems[$key] = $cartItem;
1042
+ }
1043
+ $cart['items'] = $cartItems;
1044
+ $unSerialized->cart = $cart;
1045
+ $requestParams = serialize($unSerialized);
1046
+ }
1047
+ }
1048
+ return crc32($requestParams);
1049
+ }
1050
+
1051
+
1052
+ /**
1053
+ * Checks whether some request to rates have already been done, so we have cache for it
1054
+ * Used to reduce number of same requests done to carrier service during one session
1055
+ *
1056
+ * Returns cached response or null
1057
+ *
1058
+ * @param string|array $requestParams
1059
+ * @return null|string
1060
+ */
1061
+ protected function _getCachedQuotes($requestParams)
1062
+ {
1063
+ $result = false;
1064
+ $key = $this->_getQuotesCacheKey($requestParams);
1065
+ if($this->_cacheEnabled) {
1066
+ $cache = Mage::app()->getCache();
1067
+ $result = $cache->load($key);
1068
+ if($result) {
1069
+ $result = unserialize($result);
1070
+ }
1071
+ }
1072
+ else {
1073
+ $result = isset(self::$_quotesCache[$key]) ? self::$_quotesCache[$key] : false;
1074
+ }
1075
+ return $result;
1076
+
1077
+ }
1078
+
1079
+ /**
1080
+ * Sets received carrier quotes to cache
1081
+ *
1082
+ * @param string|array $requestParams
1083
+ * @param string $response
1084
+ * @return Mage_Usa_Model_Shipping_Carrier_Abstract
1085
+ */
1086
+ protected function _setCachedQuotes($requestParams, $response)
1087
+ {
1088
+ $key = $this->_getQuotesCacheKey($requestParams);
1089
+ if($this->_cacheEnabled) {
1090
+ $cache = Mage::app()->getCache();
1091
+ $cache->save(serialize($response), $key, array("shipperhq_shipper"), 5*60);
1092
+ }
1093
+ else {
1094
+ self::$_quotesCache[$key] = $response;
1095
+ }
1096
+ return $this;
1097
+ }
1098
+
1099
+ }
app/code/community/Shipperhq/Shipper/Model/Carrier/Shipperadmin.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ /**
32
+ * Shipper shipping model
33
+ *
34
+ * @category ShipperHQ
35
+ * @package ShipperHQ_Shipper
36
+ */
37
+
38
+ class Shipperhq_Shipper_Model_Carrier_Shipperadmin
39
+ extends Mage_Shipping_Model_Carrier_Abstract
40
+ {
41
+
42
+ /**
43
+ * Identifies this shipping carrier
44
+ * @var string
45
+ */
46
+ protected $_code = 'shipperadmin';
47
+
48
+ /**
49
+ * Code for Wsalogger to pickup
50
+ *
51
+ * @var string
52
+ */
53
+ protected $_modName = 'Shipperhq_Shipper';
54
+
55
+ /**
56
+ * Collect and get rates
57
+ *
58
+ * @param Mage_Shipping_Model_Rate_Request $request
59
+ * @return Mage_Shipping_Model_Rate_Result|bool|null
60
+ */
61
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
62
+ {
63
+ if ($shipData = Mage::registry('shqadminship_data')) {
64
+ $result = Mage::getModel('shipping/rate_result');
65
+ foreach($shipData->getData() as $carrierGroupId => $rateInfo) {
66
+ $carrierGroupShippingDetail = array(
67
+ "checkoutDescription"=>$rateInfo['carriergroup'],
68
+ "name"=>$rateInfo['carriergroup'],
69
+ "carrierGroupId"=>$carrierGroupId,
70
+ "carrierType"=>"custom_admin",
71
+ "carrierTitle"=> $this->getConfigData('title'),
72
+ "carrier_code"=> $this->_code,
73
+ "carrierName"=> Mage::helper('shipperhq_shipper')->__('Custom Shipping'),
74
+ "methodTitle"=> $rateInfo['customCarrier'],
75
+ "price" => $rateInfo['customPrice'],
76
+ "cost" => $rateInfo['customPrice'],
77
+ "code"=> 'adminshipping',
78
+ );
79
+ $method = Mage::getModel('shipping/rate_result_method');
80
+ $method->setCarrier($this->_code);
81
+ $method->setPrice($rateInfo['customPrice']);
82
+ $method->setCarrierTitle($this->getConfigData('title'));
83
+ $method->setMethod('adminshipping');
84
+ $method->setMethodTitle($rateInfo['customCarrier']);
85
+ $method->setCarriergroupId($carrierGroupId);
86
+ $method->setCarriergroupShippingDetails(Mage::helper('shipperhq_shipper')->encodeShippingDetails($carrierGroupShippingDetail));
87
+ $result->append($method);
88
+ }
89
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
90
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'ShipperHQ Admin - created custom shipping rate ',
91
+ $shipData);
92
+ }
93
+ return $result;
94
+ } else {
95
+ return Mage::getModel('shipping/rate_result');
96
+ }
97
+ }
98
+
99
+ public function getAllowedMethods()
100
+ {
101
+ return array('adminshipping'=>'adminshipping');
102
+ }
103
+
104
+
105
+ }
app/code/community/Shipperhq/Shipper/Model/Checkout/Helper.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Checkout_Helper
32
+ {
33
+ /**
34
+ * Save the carrier group shipping details for single carriergroup orders and then
35
+ * return to standard Magento logic to save the method
36
+ *
37
+ * @param $shippingMethod
38
+ * @return array
39
+ */
40
+ public function saveSingleShippingMethod(Mage_Sales_Model_Quote_Address $shippingAddress, $shippingMethod)
41
+ {
42
+ if (empty($shippingMethod) ) {
43
+ $res = array(
44
+ 'error' => -1,
45
+ 'message' => Mage::helper('shipperhq_shipper')->__('Invalid Shipping Method.')
46
+ );
47
+ return $res;
48
+ }
49
+ $foundRate = $shippingAddress->getShippingRateByCode($shippingMethod);
50
+ if($foundRate) {
51
+ $shipDetails = Mage::helper('shipperhq_shipper')->decodeShippingDetails($foundRate->getCarriergroupShippingDetails());
52
+ if(array_key_exists('carrierGroupId', $shipDetails)) {
53
+ $arrayofShipDetails = array();
54
+ $arrayofShipDetails[] = $shipDetails;
55
+ $shipDetails = $arrayofShipDetails;
56
+ $encodedShipDetails = Mage::helper('shipperhq_shipper')->encodeShippingDetails($arrayofShipDetails);
57
+ }
58
+ else {
59
+ $encodedShipDetails = Mage::helper('shipperhq_shipper')->encodeShippingDetails($shipDetails);
60
+ }
61
+
62
+ $shippingAddress
63
+ ->setCarrierId($foundRate->getCarrierId())
64
+ ->setCarrierType($foundRate->getCarrierType())
65
+ ->setCarriergroupShippingDetails($encodedShipDetails)
66
+ ->setCarriergroupShippingHtml(Mage::helper('shipperhq_shipper')->getCarriergroupShippingHtml(
67
+ $encodedShipDetails))
68
+ ->setCarriergroupShippingHtml('something funny is going on')
69
+ ->save();
70
+ Mage::helper('shipperhq_shipper')->setShippingOnItems($shipDetails, $shippingAddress);
71
+
72
+ }
73
+ return array();
74
+ }
75
+
76
+ }
app/code/community/Shipperhq/Shipper/Model/Observer.php ADDED
@@ -0,0 +1,439 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Observer extends Mage_Core_Model_Abstract
32
+ {
33
+ /*
34
+ * Refresh carriers in configuration pane
35
+ *
36
+ */
37
+ public function updateTitles()
38
+ {
39
+ if(Mage::getStoreConfig('carriers/shipper/active')) {
40
+ $refreshResult = Mage::getModel('shipperhq_shipper/carrier_shipper')->refreshCarriers();
41
+ if (array_key_exists('error', $refreshResult)) {
42
+ $session = Mage::getSingleton('Mage_Adminhtml_Model_Session');
43
+ $message = $refreshResult['error'];
44
+ $session->addError($message);
45
+ } else {
46
+ $session = Mage::getSingleton('Mage_Adminhtml_Model_Session');
47
+ $message = Mage::helper('shipperhq_shipper')->__('%s shipping methods have been updated from ShipperHQ', count($refreshResult));
48
+ $session->addSuccess($message);
49
+ }
50
+ }
51
+ }
52
+
53
+ public function checkCartDisplayRequired($observer)
54
+ {
55
+ if ($block = $observer->getBlock() instanceof Mage_Checkout_Block_Cart_Shipping &&
56
+ Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
57
+ $version = Mage::helper('wsalogger')->getNewVersion();
58
+ if ($version >= 14) {
59
+ $observer->getBlock()->setTemplate('shipperhq/checkout/cart/rwd/shipping.phtml');
60
+ }
61
+ else {
62
+ $observer->getBlock()->setTemplate('shipperhq/checkout/cart/shipping.phtml');
63
+ }
64
+ }
65
+ }
66
+
67
+ /*
68
+ * Set renderer for dimensional shipping product attributes
69
+ *
70
+ */
71
+ public function catalogProductEditSetRenderer($observer)
72
+ {
73
+ $form = $observer->getForm();
74
+
75
+ $elementIds = array('shipperhq_volume_weight', 'shipperhq_poss_boxes', 'shipperhq_master_boxes'
76
+ , 'shipperhq_volume_weight');
77
+ foreach($elementIds as $element_id)
78
+ {
79
+ $element = $form->getElement($element_id);
80
+ if($element) {
81
+ $element->setRenderer(
82
+ Mage::app()->getLayout()->createBlock('shipperhq_shipper/adminhtml_catalog_product_edit_tab_dimensional')
83
+ );
84
+ }
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Add the packing boxes form when editing a product
90
+ *
91
+ * @param Varien_Event_Observer $observer
92
+ */
93
+ public function prepareProductEditFormDimensional($observer)
94
+ {
95
+
96
+ $profileElement = $observer->getEvent()->getProductElement();
97
+ // make the element dependent on shipperhq_dim_group
98
+ $dependencies = Mage::app()->getLayout()->createBlock('adminhtml/widget_form_element_dependence',
99
+ 'adminhtml_recurring_profile_edit_form_dependence')->addFieldMap('shipperhq_dim_group', 'product[shipperhq_dim_group]')
100
+ ->addFieldMap($profileElement->getHtmlId(), $profileElement->getName())
101
+ ->addFieldDependence($profileElement->getName(), 'product[shipperhq_dim_group]', '');
102
+
103
+ $dependencyOutput = $dependencies->toHtml();
104
+ $observer->getEvent()->getResult()->output .= $dependencyOutput;
105
+
106
+ }
107
+
108
+ /**
109
+ * Set flag for checkout on quote address
110
+ *
111
+ * @param object $observer
112
+ */
113
+ public function onCheckoutSaveBilling($observer)
114
+ {
115
+ $quote = Mage::helper('shipperhq_shipper')->getQuote();
116
+ $shipping = $quote->getShippingAddress();
117
+ $shipping->setIsCheckout(1);
118
+ $billing = $quote->getBillingAddress();
119
+ $billing->setIsCheckout(1);
120
+ }
121
+
122
+ public function multiCheckoutShippingPredispatch($observer)
123
+ {
124
+ $quote = $observer->getQuote();
125
+ $addresses = $quote->getAllAddresses();
126
+ foreach($addresses as $address)
127
+ {
128
+ $address->setIsCheckout(1);
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Remove flag for checkout on quote address
134
+ *
135
+ * @param object $observer
136
+ */
137
+ public function onCheckoutCartEstimatePost($observer)
138
+ {
139
+ $quote = Mage::helper('shipperhq_shipper')->getQuote();
140
+ $quote->setIsMultiShipping(false);
141
+ $shipping = $quote->getShippingAddress();
142
+ $shipping->setIsCheckout(0);
143
+ $shipping->save();
144
+ }
145
+
146
+ /*
147
+ * Set isCheckout flag on shipping address
148
+ * Collect shipping rates again when Checkout loads otherwise it caches from cart
149
+ *
150
+ *@param object $observer
151
+ */
152
+ public function onOneStepCheckoutIndex($observer)
153
+ {
154
+ $quote = Mage::helper('shipperhq_shipper')->getQuote();
155
+ $quoteStorage = Mage::helper('shipperhq_shipper')->getQuoteStorage($quote);
156
+ $shipping = $quote->getShippingAddress();
157
+ $shipping->setIsCheckout(1);
158
+ $billing = $quote->getBillingAddress();
159
+ $billing->setIsCheckout(1);
160
+ $quoteStorage->setCalendarDetails(null);
161
+ $quoteStorage->setSelectedDeliveryArray(null);
162
+ $quoteStorage->setPickupArray(null);
163
+
164
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')
165
+ && Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Splitrates')) {
166
+ // Mage::getSingleton('checkout/session')->setCarriergroupSelected(null);
167
+ $shipping->setCollectShippingRates(true);
168
+ }
169
+ }
170
+
171
+ public function saveOrderAfter($observer)
172
+ {
173
+ try
174
+ {
175
+ // $recordOrderPackages = Mage::helper('shipperhq_shipper')->recordOrderPackages();
176
+ $recordOrderPackages = true;
177
+
178
+ if ($recordOrderPackages)
179
+ {
180
+ $order = $observer->getOrder();
181
+ $quote = $order->getQuote();
182
+
183
+ $shippingAddress = $quote->getShippingAddress();
184
+ $orderId = $order->getId();
185
+ $carrierGroupDetail = json_decode($shippingAddress->getCarriergroupShippingDetails());
186
+ if(is_array($carrierGroupDetail)){
187
+ foreach($carrierGroupDetail as $carrier_group) {
188
+ if(!isset($carrier_group->carrierGroupId)) {
189
+ continue;
190
+ }
191
+ $carrierGroupId = $carrier_group->carrierGroupId;
192
+ $carrier_code = $carrier_group->carrier_code;
193
+ $shippingMethodCode = $carrier_group->code;
194
+ $packagesColl= Mage::getModel('shipperhq_shipper/quote_packages')
195
+ ->loadByCarrier($shippingAddress->getAddressId(), $carrierGroupId, $carrier_code. '_' .$shippingMethodCode);
196
+ if(count($packagesColl) < 1) {
197
+ $packagesColl= Mage::getModel('shipperhq_shipper/quote_packages')
198
+ ->loadByCarrier($shippingAddress->getAddressId(), $carrierGroupId, $carrier_code);
199
+ }
200
+ foreach ($packagesColl as $box) {
201
+ $package = Mage::getModel('shipperhq_shipper/order_packages');
202
+ $package->setOrderId($orderId);
203
+ $package->setLength($box->getLength())
204
+ ->setWidth($box->getWidth())
205
+ ->setHeight($box->getHeight())
206
+ ->setWeight($box->getWeight())
207
+ ->setPackageName($box->getPackageName())
208
+ ->setDeclaredValue($box->getDeclaredValue())
209
+ ->setSurchargePrice($box->getSurchargePrice())
210
+ ->setItems($box->getItems());
211
+ $package->save();
212
+ }
213
+ if($recordOrderPackages && count($packagesColl) > 0)
214
+ {
215
+ $boxText = Mage::helper('shipperhq_shipper')->getPackageBreakdownText($packagesColl);
216
+ $order->addStatusToHistory($order->getStatus(), $boxText, false);
217
+ }
218
+ $order->addStatusToHistory($order->getStatus(), 'ShipperHQ Transaction ID: ' .$carrier_group->transaction, false);
219
+ $order->save();
220
+
221
+ }
222
+ }
223
+ else {
224
+ $shippingMethod = $order->getShippingMethod();
225
+ if($rate = $quote->getShippingAddress()->getShippingRateByCode($shippingMethod)) {
226
+ $packagesColl= Mage::getModel('shipperhq_shipper/quote_packages')
227
+ ->loadByCarrier($shippingAddress->getAddressId(), null, $rate->getCarrier());
228
+ foreach ($packagesColl as $box) {
229
+ $package = Mage::getModel('shipperhq_shipper/order_packages');
230
+ $package->setOrderId($orderId);
231
+ $package->setLength($box->getLength())
232
+ ->setWidth($box->getWidth())
233
+ ->setHeight($box->getHeight())
234
+ ->setWeight($box->getWeight())
235
+ ->setPackageName($box->getPackageName())
236
+ ->setDeclaredValue($box->getDeclaredValue())
237
+ ->setSurchargePrice($box->getSurchargePrice())
238
+ ->setItems($box->getItems());
239
+ $package->save();
240
+ }
241
+ if($recordOrderPackages && count($packagesColl) > 0)
242
+ {
243
+ $boxText = Mage::helper('shipperhq_shipper')->getPackageBreakdownText($packagesColl);
244
+ $order->addStatusToHistory($order->getStatus(), $boxText, false);
245
+ $order->save();
246
+ }
247
+ }
248
+
249
+ }
250
+ }
251
+ }
252
+ catch (Exception $e) {
253
+ Mage::logException($e);
254
+ }
255
+ }
256
+
257
+ /*
258
+ * Process admin shipping
259
+ */
260
+ public function adminSalesOrderCreateProcessDataBefore($observer)
261
+ {
262
+ if(Mage::getStoreConfig('carriers/shipper/active')) {
263
+ $post = $observer->getRequestModel()->getPost();
264
+ if(isset($post['order'])) {
265
+ $data = $post['order'];
266
+ $found = false;
267
+ $customCarrierGroupData = array();
268
+
269
+ if (isset($data['shipping_amount'])) {
270
+ $customCarrierGroupData[''] = array('customPrice' => $data['shipping_amount'], 'carriergroup' => '');
271
+ $found = true;
272
+ }
273
+
274
+ if (isset($data['shipping_description'])) {
275
+ if(array_key_exists('', $customCarrierGroupData)) {
276
+ $shipArray = $customCarrierGroupData[''];
277
+ $shipArray['customCarrier'] = $data['shipping_description'];
278
+ $customCarrierGroupData[''] = $shipArray;
279
+ }
280
+ else {
281
+ $customCarrierGroupData[''] = array('customCarrier' => $data['shipping_description'], 'carriergroup' => '');
282
+ }
283
+ $found = true;
284
+ }
285
+
286
+ if ($found) {
287
+ $shippingAddress = $observer->getSession()->getQuote()->getShippingAddress();
288
+ Mage::helper('shipperhq_shipper')->cleanDownRatesCollection($shippingAddress, 'shipperadmin', '');
289
+ Mage::register('shqadminship_data', new Varien_Object($customCarrierGroupData));
290
+ $storedLimitCarrier = $shippingAddress->getLimitCarrier();
291
+ $shippingAddress->setLimitCarrier('shipperadmin');
292
+ $rateFound = $shippingAddress->requestShippingRates();
293
+ $shippingAddress->setLimitCarrier($storedLimitCarrier);
294
+ } else {
295
+ Mage::unregister('shqadminship_data');
296
+ }
297
+ }
298
+ }
299
+ }
300
+
301
+ public function salesConvertQuoteItemToOrderItem($observer)
302
+ {
303
+ try {
304
+ if (!Mage::getStoreConfig('carriers/shipper/active')) {
305
+ return;
306
+ }
307
+ $quoteItem = $observer->getEvent()->getItem();
308
+ $orderItem = $observer->getEvent()->getOrderItem();
309
+ $carriergroupId = $quoteItem->getCarriergroupId();
310
+
311
+ $orderItem->setCarriergroupId($carriergroupId);
312
+ $orderItem->setCarriergroup($quoteItem->getCarriergroup());
313
+ } catch (Exception $e) {
314
+ Mage::logException($e);
315
+ }
316
+
317
+ }
318
+
319
+ protected function _getCheckout()
320
+ {
321
+ return Mage::getSingleton('checkout/session');
322
+ }
323
+
324
+ public function setCurrentQuoteObjectInAdmin(Varien_Event_Observer $observer)
325
+ {
326
+ Mage::helper('shipperhq_shipper')->setQuote(
327
+ Mage::getSingleton('adminhtml/sales_order_create')->getQuote()
328
+ );
329
+ }
330
+
331
+ public function setCurrentQuoteObjectInAdminFromSaveData(Varien_Event_Observer $observer)
332
+ {
333
+
334
+ $quote = $observer->getOrderCreateModel()->getQuote();
335
+ $shipping = $quote->getShippingAddress();
336
+ $shipping->setIsCheckout(1);
337
+ $billing = $quote->getBillingAddress();
338
+ $billing->setIsCheckout(1);
339
+
340
+ $request = $observer->getRequestModel();
341
+ if ($request->getActionName() === 'save') {
342
+ $orderData = $request->getPost('order');
343
+
344
+ if (isset($orderData['shipping_address'])) {
345
+ unset($orderData['shipping_address']);
346
+ }
347
+
348
+ if (isset($orderData['billing_address'])) {
349
+ unset($orderData['billing_address']);
350
+ }
351
+
352
+ if (isset($orderData['shipping_method'])) {
353
+ unset($orderData['shipping_method']);
354
+ }
355
+
356
+ $request->setPost('order', $orderData);
357
+ $request->setPost('shipping_as_billing', 0);
358
+ }
359
+
360
+ Mage::helper('shipperhq_shipper')->setQuote($observer->getOrderCreateModel()->getQuote());
361
+ }
362
+
363
+ /**
364
+ * Loads storage data for quote if it was not loaded
365
+ *
366
+ * @param Varien_Event_Observer $observer
367
+ */
368
+ public function onQuoteAfterLoad(Varien_Event_Observer $observer)
369
+ {
370
+ $quote = $observer->getQuote();
371
+ Mage::helper('shipperhq_shipper')->getQuoteStorage($quote);
372
+ }
373
+
374
+ /**
375
+ * Saves storage data if quote is saved
376
+ *
377
+ * @param Varien_Event_Observer $observer
378
+ * @return $this
379
+ * @throws Exception
380
+ */
381
+ public function onQuoteAfterSave(Varien_Event_Observer $observer)
382
+ {
383
+ $quote = $observer->getQuote();
384
+ $storage = Mage::helper('shipperhq_shipper')->storageManager()->findByQuote($quote);
385
+ $this->_saveStorageInstance($storage);
386
+ return $this;
387
+ }
388
+
389
+ /**
390
+ * Saves modified data objects on post dispatch,
391
+ * if modifications has been done after quote has been saved
392
+ *
393
+ *
394
+ */
395
+ public function onPostDispatch()
396
+ {
397
+ /** @var Shipperhq_Shipper_Model_Storage[] $storageList */
398
+ $storageList = Mage::helper('shipperhq_shipper')->storageManager()->getStorageObjects();
399
+ foreach ($storageList as $storage) {
400
+ if ($storage->hasDataChanges() && $storage->getId()) {
401
+ $this->_saveStorageInstance($storage);
402
+ }
403
+ }
404
+ }
405
+
406
+ /**
407
+ * Saves storage instance
408
+ *
409
+ * @param Shipperhq_Shipper_Model_Storage $storage
410
+ * @return $this
411
+ * @throws Exception
412
+ */
413
+ protected function _saveStorageInstance(Shipperhq_Shipper_Model_Storage $storage)
414
+ {
415
+ if ($storage->isLoaded() && $storage->isEmpty()) {
416
+ // When object is empty, we delete database record
417
+ $storage->isDeleted(true);
418
+ } elseif ($storage->isEmpty()) {
419
+ // If object is new and has no data, than do not save
420
+ return $this;
421
+ } elseif ($storage->isDeleted()) {
422
+ // If it was deleted, remove a flag
423
+ $storage->isDeleted(false);
424
+ }
425
+
426
+ if (!$storage->isValid(true)) {
427
+ return $this;
428
+ }
429
+
430
+ try {
431
+ $storage->save();
432
+ } catch (Exception $e) {
433
+ Mage::logException($e);
434
+ // Do not break quote save process
435
+ }
436
+
437
+ return $this;
438
+ }
439
+ }
app/code/community/Shipperhq/Shipper/Model/Observer/Order.php ADDED
@@ -0,0 +1,446 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ include_once 'ShipperHQ/WS/Client/WebServiceClient.php';
32
+ include_once 'ShipperHQ/WS/Response/ErrorMessages.php';
33
+
34
+ class Shipperhq_Shipper_Model_Observer_Order extends Mage_Core_Model_Abstract
35
+ {
36
+
37
+ protected $_shipperWSInstance = null;
38
+
39
+ /*
40
+ * Process shipping method and save and perform reserve Order if required
41
+ *
42
+ */
43
+ public function saveShippingMethod($observer)
44
+ {
45
+ $request = $observer->getEvent()->getRequest();
46
+ if(!$shippingMethod = $request->getPost('shipping_method', '')) {
47
+ return;
48
+ }
49
+ if(!Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
50
+ return;
51
+ }
52
+ $quote = $observer->getEvent()->getQuote();
53
+ $helper = Mage::getSingleton('shipperhq_shipper/checkout_helper');
54
+ $helper->saveSingleShippingMethod($quote->getShippingAddress(), $shippingMethod);
55
+
56
+ $rate = $quote->getShippingAddress()->getShippingRateByCode($shippingMethod);
57
+ if(!$rate) {
58
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
59
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper',
60
+ 'save Shipping Method', "Can't find rate for selected shipping method of " .$shippingMethod);
61
+ }
62
+ return;
63
+ }
64
+
65
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Pbint') &&
66
+ Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
67
+ $quote = $observer->getQuote();
68
+ $address = $quote->getShippingAddress();
69
+ $pbHelper = Mage::getModel('shipperhq_pbint/helper');
70
+ $pbHelper->cleanDownSession();
71
+
72
+ if (Mage::helper('shipperhq_pbint')->isPbOrder($address->getCarrierType())) {
73
+
74
+ $result = $this->reserveOrder($pbHelper, $address, $rate->getCarrier(), $rate->getCarriergroupId());
75
+ }
76
+ else {
77
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
78
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper',
79
+ '', "Selected shipping method is NOT ShipperHQ Pitney");
80
+ }
81
+ return;
82
+ }
83
+ }
84
+
85
+ }
86
+
87
+ /*
88
+ * Process shipping method and save and perform reserve Order if required
89
+ *
90
+ */
91
+ public function saveShippingMethodMulti($observer)
92
+ {
93
+ if(!Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
94
+ return;
95
+ }
96
+ try {
97
+ $processPitney = false;
98
+
99
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Pbint') &&
100
+ Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
101
+ $processPitney = true;
102
+ $pbHelper = Mage::getModel('shipperhq_pbint/helper');
103
+ }
104
+ $request = $observer->getEvent()->getRequest();
105
+ $shippingMethods = $request->getPost('shipping_method', '');
106
+ if(!is_array($shippingMethods)) {
107
+ return;
108
+ }
109
+ foreach($shippingMethods as $addressId => $shippingMethod) {
110
+ if (empty($shippingMethod)) {
111
+ return;
112
+ }
113
+ $quote = $observer->getEvent()->getQuote();
114
+ $addresses = $quote->getAllShippingAddresses();
115
+ $shippingAddress = false;
116
+ foreach($addresses as $address) {
117
+ if($address->getId() == $addressId) {
118
+ $shippingAddress = $address;
119
+ break;
120
+ }
121
+
122
+ }
123
+ $rate = $shippingAddress->getShippingRateByCode($shippingMethod);
124
+ if (!$rate) {
125
+ continue;
126
+ }
127
+
128
+ $helper = Mage::getSingleton('shipperhq_shipper/checkout_helper');
129
+ $helper->saveSingleShippingMethod($shippingAddress, $shippingMethod);
130
+
131
+ $shippingAddress
132
+ ->setCarrierType($rate->getCarrierType())
133
+ ->setCarrierId($rate->getCarrierId())
134
+ ->save();
135
+
136
+ if ($processPitney) {
137
+ if(Mage::helper('shipperhq_pbint')->isPbOrder($address->getCarrierType())) {
138
+ $result = $this->reserveOrder($pbHelper, $address, $rate->getCarrier(), $rate->getCarriergroupId());
139
+ }
140
+ else {
141
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
142
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper',
143
+ '', "Selected shipping method is NOT ShipperHQ Pitney");
144
+ }
145
+ //TODO handle when one is and one isn't Pitney - it will wipe here ?
146
+ $pbHelper->cleanDownSession();
147
+ }
148
+ }
149
+
150
+ }
151
+ }catch (Exception $e) {
152
+ Mage::logException($e);
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Save shipping breakdown per carrier group
158
+ * @param $observer
159
+ */
160
+ public function saveShippingMethodAdmin($observer)
161
+ {
162
+ if(!Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
163
+ return;
164
+ }
165
+ $requestData = $observer->getRequestModel()->getPost();
166
+ $orderData = array();
167
+ if (isset($requestData['order'])) {
168
+ $orderData = $requestData['order'];
169
+ }
170
+ if(!empty($requestData['shipping_method_flag'])) {
171
+ $orderData = $requestData;
172
+ }
173
+ $quote = $observer->getOrderCreateModel()->getQuote();
174
+ Mage::helper('shipperhq_shipper')->setQuote($quote);
175
+
176
+ if (!empty($orderData['shipping_method_flag'])) {
177
+ if (!empty($orderData['shipping_method'])) {
178
+ $shippingMethod = $orderData['shipping_method'];
179
+ $helper = Mage::getSingleton('shipperhq_shipper/checkout_helper');
180
+ $helper->saveSingleShippingMethod($quote->getShippingAddress(), $shippingMethod);
181
+
182
+ $rate = $quote->getShippingAddress()->getShippingRateByCode($shippingMethod);
183
+ if(!$rate) {
184
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
185
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper',
186
+ 'save Shipping Method', "Can't find rate for selected shipping method of " .$shippingMethod);
187
+ }
188
+ return;
189
+ }
190
+
191
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Pbint') &&
192
+ Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
193
+ $address = $quote->getShippingAddress();
194
+ $pbHelper = Mage::getModel('shipperhq_pbint/helper');
195
+ $pbHelper->cleanDownSession();
196
+
197
+ if (Mage::helper('shipperhq_pbint')->isPbOrder($address->getCarrierType())) {
198
+
199
+ $result = $this->reserveOrder($pbHelper, $address, $rate->getCarrier(), $rate->getCarriergroupId());
200
+ }
201
+ else {
202
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
203
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper',
204
+ '', "Selected shipping method is NOT ShipperHQ Pitney");
205
+ }
206
+ }
207
+ }
208
+ $requestData['order']['shipping_method'] = $orderData['shipping_method'];
209
+ }
210
+ $observer->getRequestModel()->setPost($requestData);
211
+ }
212
+ }
213
+
214
+ /*
215
+ *
216
+ */
217
+ public function preDispatchSetMethodsSeparate($observer)
218
+ {
219
+ if(!Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
220
+ return;
221
+ }
222
+ $controller = $observer->getControllerAction();
223
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
224
+ $quoteStorage = Mage::helper('shipperhq_shipper')->getQuoteStorage($quote);
225
+
226
+ if ($controller->getRequest()->isPost()) {
227
+ $shippingMethod = $controller->getRequest()->getPost('shipping_method', '');
228
+ if (empty($shippingMethod)) {
229
+ return;
230
+ }
231
+
232
+ $helper = Mage::getSingleton('shipperhq_shipper/checkout_helper');
233
+ $helper->saveSingleShippingMethod($quote->getShippingAddress(), $shippingMethod);
234
+
235
+ $rate = $quote->getShippingAddress()->getShippingRateByCode($shippingMethod);
236
+ if(!$rate) {
237
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
238
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper',
239
+ 'setMethodsSeparate', "Can't find rate for selected shipping method of " .$shippingMethod);
240
+ }
241
+ return;
242
+ }
243
+
244
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Pbint') &&
245
+ Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
246
+ $address = $quote->getShippingAddress();
247
+ $pbHelper = Mage::getModel('shipperhq_pbint/helper');
248
+ $pbHelper->cleanDownSession();
249
+
250
+ if (Mage::helper('shipperhq_pbint')->isPbOrder($address->getCarrierType())) {
251
+
252
+ $result = $this->reserveOrder($pbHelper, $address, $rate->getCarrier(), $rate->getCarriergroupId());
253
+ }
254
+ else {
255
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
256
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper',
257
+ '', "Selected shipping method is NOT ShipperHQ Pitney");
258
+ }
259
+ }
260
+ }
261
+
262
+ }
263
+ }
264
+
265
+ /*
266
+ * Confirm Order action
267
+ *
268
+ */
269
+ public function checkoutOnepageSuccess($observer)
270
+ {
271
+ if(!Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
272
+ return;
273
+ }
274
+ $mageOrderNumber = Mage::getSingleton('checkout/session')->getLastRealOrderId();
275
+ $order = Mage::getModel('sales/order')->loadByIncrementId($mageOrderNumber);
276
+ if($order->getIncrementId()) {
277
+ $this->confirmOrder($order);
278
+ }
279
+ }
280
+
281
+ public function checkoutMulitaddressSuccess($observer)
282
+ {
283
+ if(!Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
284
+ return;
285
+ }
286
+ $orderIds = $observer->getEvent()->getOrderIds();
287
+ if (empty($orderIds) || !is_array($orderIds)) {
288
+ return;
289
+ }
290
+ foreach($orderIds as $orderId) {
291
+ $order = Mage::getModel('sales/order')->load($orderId);
292
+ if($order->getIncrementId()) {
293
+ $this->confirmOrder($order);
294
+ }
295
+ }
296
+ }
297
+
298
+ public function adminOrderSaveAfter($observer)
299
+ {
300
+ if(!Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
301
+ return;
302
+ }
303
+ $order = $observer->getEvent()->getOrder();
304
+ if($order->getIncrementId()) {
305
+ $this->confirmOrder($order);
306
+ }
307
+
308
+ }
309
+
310
+ protected function confirmOrder($order)
311
+ {
312
+ $confirm = false;
313
+ $customOrderId = null;
314
+ $pitney = false;
315
+ $orderId = $order->getIncrementId();
316
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Pbint') &&
317
+ Mage::helper('shipperhq_pbint')->isPbOrder($order->getCarrierType())) {
318
+ $helper = Mage::getModel('shipperhq_pbint/helper');
319
+ $pitney = true;
320
+ if ($customOrderId = $helper->confirmOrderRequired($orderId)) {
321
+ $confirm = true;
322
+ } else {
323
+ if (Mage::helper('shipperhq_pbint')->isDebug()) {
324
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
325
+ 'Confirm order observer', $orderId . ' is not a Pitney Order Number');
326
+
327
+ }
328
+ $helper->cleanDownSession();
329
+ }
330
+
331
+ }
332
+
333
+ if(Mage::helper('shipperhq_shipper')->isConfirmOrderRequired($order->getCarrierType())) {
334
+ $confirm = true;
335
+
336
+ }
337
+ if($confirm) {
338
+ $quoteId = $order->getQuoteId();
339
+ if($quoteId && $quote = Mage::getModel('sales/quote')->load($quoteId)) {
340
+
341
+ $request = Mage::getSingleton('Shipperhq_Shipper_Model_Carrier_Convert_OrderMapper')->
342
+ getOrderTranslation($order, $quote, $customOrderId);
343
+ $timeout = Mage::helper('shipperhq_shipper')->getWebserviceTimeout();
344
+ $response = $this->_getShipperInstance()->sendAndReceive($request,
345
+ Mage::helper('shipperhq_shipper')->getConfirmOrderGatewayUrl(), $timeout);
346
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
347
+ $request = json_decode($response['debug']['json_request']);
348
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper',
349
+ 'Confirm order request',$request);
350
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
351
+ 'Confirm order response', $response['result']);
352
+ }
353
+ if($response && isset($response['result'])) {
354
+ $result = $this->processConfirmOrderResponse($response['result'], $order);
355
+ if($pitney) {
356
+ $result = $helper->processConfirmOrderResponse($response['result']);
357
+ }
358
+
359
+ }
360
+ }
361
+
362
+ }
363
+ if(strstr($order->getCarrierType(), 'shqshared_')) {
364
+ $carrierTypeArray = explode('_', $order->getCarrierType());
365
+ if(is_array($carrierTypeArray)) {
366
+ $order->setCarrierType($carrierTypeArray[1]);
367
+ $order->save();
368
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
369
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'Rates displayed as single carrier',
370
+ 'Resetting carrier type on order to be ' .$carrierTypeArray[1]);
371
+ }
372
+ }
373
+ }
374
+ }
375
+
376
+ protected function reserveOrder($helper, $address, $carrierCode, $carriergroupId)
377
+ {
378
+ $request = Mage::getSingleton('Shipperhq_Shipper_Model_Carrier_Convert_AddressMapper')->
379
+ getAddressTranslation($address, $carrierCode, $carriergroupId);
380
+ $timeout = Mage::helper('shipperhq_shipper')->getWebserviceTimeout();
381
+ $response = $this->_getShipperInstance()->sendAndReceive($request,
382
+ Mage::helper('shipperhq_shipper')->getReserveOrderGatewayUrl(), $timeout);
383
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
384
+ $request = $response['debug']['json_request'];
385
+ $request = json_decode($request);
386
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
387
+ 'Reserve order request', $request);
388
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
389
+ 'Reserve order response', $response['result']);
390
+ }
391
+ if($response && isset($response['result'])) {
392
+ $result = $helper->processReserveOrderResponse($response['result']);
393
+ }
394
+ else {
395
+ $result = false;
396
+ }
397
+ return $result;
398
+ }
399
+
400
+
401
+ protected function _getShipperInstance()
402
+ {
403
+ if (empty($this->_shipperWSInstance)) {
404
+ $this->_shipperWSInstance = new \ShipperHQ\WS\Client\WebServiceClient();
405
+ }
406
+ return $this->_shipperWSInstance;
407
+ }
408
+
409
+ protected function processConfirmOrderResponse($response, $order)
410
+ {
411
+ if(!is_object($response)) {
412
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
413
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Shipper',
414
+ 'Process Confirm Order did not return a response', $response);
415
+ }
416
+ return;
417
+ }
418
+ $errors = (array)$response->errors;
419
+ $responseSummary = (array)$response->responseSummary;
420
+ $result = isset($response->result) ? (array)$response->result : false;
421
+ if(($errors && count($errors) > 0) || $responseSummary['status'] != 1) {
422
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
423
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Shipper',
424
+ 'Error confirming order', $response);
425
+ }
426
+ }
427
+ elseif(in_array('SUCCCESS', $result)) {
428
+ $confirmationNumber = $response->confirmationNo;
429
+ try {
430
+ $order->setConfirmationNumber($confirmationNumber);
431
+ $order->save();
432
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
433
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper',
434
+ 'Confirmed order with Shipperhq', $confirmationNumber);
435
+ }
436
+ }
437
+ catch(Exception $e) {
438
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
439
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Shipper',
440
+ 'Confirm order response processing, error', $e->getMessage());
441
+ }
442
+ }
443
+ }
444
+ }
445
+
446
+ }
app/code/community/Shipperhq/Shipper/Model/Observer/Shipment.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ include_once 'ShipperHQ/WS/Client/WebServiceClient.php';
32
+ include_once 'ShipperHQ/WS/Response/ErrorMessages.php';
33
+
34
+ class Shipperhq_Shipper_Model_Observer_Shipment extends Mage_Core_Model_Abstract
35
+ {
36
+ protected $_shipperWSInstance = null;
37
+
38
+ /*
39
+ * Process shipment additional information
40
+ *
41
+ */
42
+ public function processShipmentAddon($observer)
43
+ {
44
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Pbint') &&
45
+ Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Shipper', 'carriers/shipper/active')) {
46
+ //if pitney order required
47
+ $helper = Mage::getModel('shipperhq_pbint/helper');
48
+ $shipment = $observer->getShipment();
49
+ if ($helper->analyzeProcessShipment($shipment)) {
50
+ $shipment = $observer->getShipment();
51
+ $order = $shipment->getOrder();
52
+ if($order) {
53
+ //this should be keyed off the shipment ID not the order id I believe, so we can have more than one shipment per order
54
+ $pbOrders = Mage::getModel("shipperhq_pbint/ordernumber")->getCollection();
55
+ $pbOrders->addFieldToFilter('mage_order_number', $order->getRealOrderId());
56
+ $result = false;
57
+
58
+ foreach ($pbOrders as $oneOrder) {
59
+ $pitneyOrderId = $oneOrder->getCpOrderNumber();
60
+ $tracks = array();
61
+ foreach($shipment->getTracksCollection() as $track) {
62
+ $tracks[] = $track;
63
+ }
64
+ $packagesColl= Mage::getModel('shipperhq_shipper/order_packages')
65
+ ->loadByOrderId($order->getId());
66
+ foreach($packagesColl as $package) {
67
+ $request = Mage::getSingleton('Shipperhq_Shipper_Model_Carrier_Convert_ShipmentMapper')->
68
+ getShipmentTranslation($order, $shipment, $package, $pitneyOrderId);
69
+ $timeout = Mage::helper('shipperhq_shipper')->getWebserviceTimeout();
70
+ $response = $this->_getShipperInstance()->sendAndReceive($request,
71
+ Mage::helper('shipperhq_shipper')->getShipmentAddonGatewayUrl(), $timeout);
72
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
73
+ $request = json_decode($response['debug']['json_request']);
74
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper',
75
+ 'Process Shipment Add On request',$request);
76
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Pbint',
77
+ 'Process Shipment Add On response', $response['result']);
78
+ }
79
+ if($response && isset($response['result'])) {
80
+ $result = $helper->processShipmentAddonResponse($shipment, $response['result'], $pitneyOrderId);
81
+ }
82
+ else {
83
+ $result = false;
84
+ }
85
+ }
86
+
87
+ }
88
+ return $result;
89
+
90
+ }
91
+ }
92
+
93
+ return false;
94
+
95
+ }
96
+ }
97
+
98
+
99
+ protected function _getShipperInstance()
100
+ {
101
+ if (empty($this->_shipperWSInstance)) {
102
+ $this->_shipperWSInstance = new \ShipperHQ\WS\Client\WebServiceClient();
103
+ }
104
+ return $this->_shipperWSInstance;
105
+ }
106
+
107
+ }
app/code/community/Shipperhq/Shipper/Model/Order/Packages.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ *
30
+ *
31
+ */
32
+ class Shipperhq_Shipper_Model_Order_Packages
33
+ extends Mage_Core_Model_Abstract
34
+ {
35
+ /**
36
+ * Packages stored for quote
37
+ *
38
+ */
39
+ protected function _construct()
40
+ {
41
+ $this->_init('shipperhq_shipper/order_packages');
42
+ }
43
+
44
+ /**
45
+ * Loads data by quote object
46
+ *
47
+ * @param Mage_Sales_Model_Quote $quote
48
+ * @return $this
49
+ */
50
+ public function loadByCarriergroup($orderId, $carrierGroupId)
51
+ {
52
+ $collection = $this->getResourceCollection()
53
+ ->addOrderToFilter($orderId)
54
+ ->addCarrierGroupToFilter($carrierGroupId);
55
+
56
+ foreach($collection as $package)
57
+ {
58
+ $package->load($package->getId());
59
+ }
60
+ return $collection;
61
+ }
62
+
63
+ public function loadByOrderId($orderId)
64
+ {
65
+ $collection = $this->getResourceCollection()
66
+ ->addOrderToFilter($orderId);
67
+
68
+ foreach($collection as $package)
69
+ {
70
+ $package->load($package->getId());
71
+ }
72
+ return $collection;
73
+ }
74
+
75
+ /**
76
+ *
77
+ *
78
+ * @return Mage_Core_Model_Abstract
79
+ */
80
+ protected function _beforeSave()
81
+ {
82
+ return parent::_beforeSave();
83
+ }
84
+
85
+
86
+
87
+ }
app/code/community/Shipperhq/Shipper/Model/Quote/Packages.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ *
30
+ *
31
+ */
32
+ class Shipperhq_Shipper_Model_Quote_Packages
33
+ extends Mage_Core_Model_Abstract
34
+ {
35
+ /**
36
+ * Packages stored for quote
37
+ *
38
+ */
39
+ protected function _construct()
40
+ {
41
+ $this->_init('shipperhq_shipper/quote_packages');
42
+ }
43
+
44
+ /**
45
+ * Loads data by quote object
46
+ *
47
+ * @param Mage_Sales_Model_Quote $quote
48
+ * @return $this
49
+ */
50
+ public function loadByCarrier($addressId, $carrierGroupId, $carrierCode)
51
+ {
52
+ $collection = $this->getResourceCollection()
53
+ ->addAddressToFilter($addressId)
54
+ ->addCarrierCodeToFilter($carrierCode);
55
+ if(!is_null($carrierGroupId)) {
56
+ $collection->addCarrierGroupToFilter($carrierGroupId);
57
+ }
58
+
59
+ foreach($collection as $package)
60
+ {
61
+ $package->load($package->getId());
62
+ }
63
+ return $collection;
64
+ }
65
+
66
+
67
+ /**
68
+ *
69
+ *
70
+ * @return Mage_Core_Model_Abstract
71
+ */
72
+ protected function _beforeSave()
73
+ {
74
+ return parent::_beforeSave();
75
+ }
76
+
77
+
78
+
79
+ }
app/code/community/Shipperhq/Shipper/Model/Rate/Result.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Shipping
23
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+ /**
27
+ *
28
+ * Webshopapps Shipping Module
29
+ *
30
+ * NOTICE OF LICENSE
31
+ *
32
+ * This source file is subject to the Open Software License (OSL 3.0)
33
+ * that is bundled with this package in the file LICENSE.txt.
34
+ * It is also available through the world-wide-web at this URL:
35
+ * http://opensource.org/licenses/osl-3.0.php
36
+ * If you did not receive a copy of the license and are unable to
37
+ * obtain it through the world-wide-web, please send an email
38
+ * to license@magentocommerce.com so we can send you a copy immediately.
39
+ *
40
+ * DISCLAIMER
41
+ *
42
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
43
+ * versions in the future. If you wish to customize Magento for your
44
+ * needs please refer to http://www.magentocommerce.com for more information.
45
+ *
46
+ * Shipper HQ Shipping
47
+ *
48
+ * @category ShipperHQ
49
+ * @package ShipperHQ_Shipping_Carrier
50
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
51
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
52
+ * @author ShipperHQ Team sales@shipperhq.com
53
+ */
54
+ /**
55
+ * Shipper shipping model
56
+ *
57
+ * @category ShipperHQ
58
+ * @package ShipperHQ_Shipper
59
+ */
60
+
61
+ class Shipperhq_Shipper_Model_Rate_Result extends Mage_Shipping_Model_Rate_Result
62
+ {
63
+ /**
64
+ * Sort rates by price from min to max
65
+ *
66
+ * @return Mage_Shipping_Model_Rate_Result
67
+ */
68
+ public function sortRatesByPrice ()
69
+ {
70
+ return;
71
+ // dont do anything - leave to the shipping extension
72
+ }
73
+ }
app/code/community/Shipperhq/Shipper/Model/Resource/Attributeupdate.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Resource_Attributeupdate extends Mage_Core_Model_Mysql4_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ $this->_init('shipperhq_shipper/attributeupdate', 'synch_id');
36
+ }
37
+ }
app/code/community/Shipperhq/Shipper/Model/Resource/Attributeupdate/Collection.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Resource_Attributeupdate_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ parent::_construct();
36
+ $this->_init('shipperhq_shipper/attributeupdate');
37
+ }
38
+ }
app/code/community/Shipperhq/Shipper/Model/Resource/Order/Packages.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Resource_Order_Packages extends Mage_Core_Model_Mysql4_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ $this->_init('shipperhq_shipper/order_packages', 'package_id');
36
+ }
37
+
38
+ protected function _afterLoad(Mage_Core_Model_Abstract $object) {
39
+ parent::_afterLoad($object);
40
+
41
+ $itemSelect = $this->_getReadAdapter()->select()
42
+ ->from($this->getTable('order_package_items'))
43
+ ->where('package_id=?', $object->getId());
44
+
45
+ $items = $this->_getReadAdapter()->fetchAll($itemSelect);
46
+
47
+ $object->setItems($items);
48
+ return $this;
49
+ }
50
+
51
+
52
+ protected function _afterSave(Mage_Core_Model_Abstract $object) {
53
+ parent::_afterSave($object);
54
+
55
+ // now save the package items
56
+ try {
57
+ $condition = $this->_getWriteAdapter()->quoteInto('package_id = ?', $object->getId());
58
+ $this->_getWriteAdapter()->delete($this->getTable('order_package_items'), $condition);
59
+ foreach ($object->getData('items') as $item) {
60
+ $itemInsert = new Varien_Object();
61
+ $itemInsert->setData('package_id',$object->getId());
62
+ $itemInsert->setSku($item['sku']);
63
+ $itemInsert->setWeightPacked($item['weight_packed']);
64
+ $itemInsert->setQtyPacked($item['qty_packed']);
65
+ $this->_getWriteAdapter()->insert($this->getTable('order_package_items'), $itemInsert->getData());
66
+ }
67
+ $this->_getWriteAdapter()->commit();
68
+
69
+ }
70
+ catch (Exception $e) {
71
+ Mage::throwException($e);
72
+ $this->_getWriteAdapter()->rollBack();
73
+ }
74
+ return $this;
75
+ }
76
+ }
app/code/community/Shipperhq/Shipper/Model/Resource/Order/Packages/Collection.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Resource_Order_Packages_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ parent::_construct();
36
+ $this->_init('shipperhq_shipper/order_packages');
37
+ }
38
+
39
+ public function addOrderToFilter($orderId)
40
+ {
41
+ $this->addFieldToFilter('order_id', $orderId);
42
+ return $this;
43
+ }
44
+
45
+ public function addCarrierGroupToFilter($carrierGroupId)
46
+ {
47
+ $this->addFieldToFilter('carrier_group_id', $carrierGroupId);
48
+ return $this;
49
+ }
50
+ }
app/code/community/Shipperhq/Shipper/Model/Resource/Quote/Packages.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Resource_Quote_Packages extends Mage_Core_Model_Mysql4_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ $this->_init('shipperhq_shipper/quote_packages', 'package_id');
36
+ }
37
+
38
+ protected function _afterLoad(Mage_Core_Model_Abstract $object) {
39
+ parent::_afterLoad($object);
40
+
41
+ $itemSelect = $this->_getReadAdapter()->select()
42
+ ->from($this->getTable('quote_package_items'))
43
+ ->where('package_id=?', $object->getId());
44
+
45
+ $items = $this->_getReadAdapter()->fetchAll($itemSelect);
46
+
47
+ $object->setItems($items);
48
+ return $this;
49
+ }
50
+
51
+
52
+ protected function _afterSave(Mage_Core_Model_Abstract $object) {
53
+ parent::_afterSave($object);
54
+
55
+ // now save the package items
56
+ try {
57
+ $condition = $this->_getWriteAdapter()->quoteInto('package_id = ?', $object->getId());
58
+ $this->_getWriteAdapter()->delete($this->getTable('quote_package_items'), $condition);
59
+ foreach ($object->getData('items') as $item) {
60
+ $itemInsert = new Varien_Object();
61
+ $itemInsert->setData('package_id',$object->getId());
62
+ $itemInsert->setSku($item->sku);
63
+ $itemInsert->setWeightPacked($item->weightPacked);
64
+ $itemInsert->setQtyPacked($item->qtyPacked);
65
+ $this->_getWriteAdapter()->insert($this->getTable('quote_package_items'), $itemInsert->getData());
66
+ }
67
+ $this->_getWriteAdapter()->commit();
68
+
69
+ }
70
+ catch (Exception $e) {
71
+ Mage::throwException($e);
72
+ $this->_getWriteAdapter()->rollBack();
73
+ }
74
+ return $this;
75
+ }
76
+ }
app/code/community/Shipperhq/Shipper/Model/Resource/Quote/Packages/Collection.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Resource_Quote_Packages_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
32
+ {
33
+ public function _construct()
34
+ {
35
+ parent::_construct();
36
+ $this->_init('shipperhq_shipper/quote_packages');
37
+ }
38
+
39
+ public function addAddressToFilter($addressId)
40
+ {
41
+ $this->addFieldToFilter('address_id', $addressId);
42
+ return $this;
43
+ }
44
+ public function addCarrierCodeToFilter($carrierCode)
45
+ {
46
+ $this->addFieldToFilter('carrier_code', $carrierCode);
47
+ return $this;
48
+ }
49
+
50
+ public function addCarrierGroupToFilter($carrierGroupId)
51
+ {
52
+ $this->addFieldToFilter('carrier_group_id', $carrierGroupId);
53
+ return $this;
54
+ }
55
+ }
app/code/community/Shipperhq/Shipper/Model/Resource/Storage.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Resource_Storage
32
+ extends Mage_Core_Model_Resource_Db_Abstract
33
+ {
34
+ /**
35
+ * Storage is going to be fully attached to quote
36
+ *
37
+ * @var bool
38
+ */
39
+ protected $_isPkAutoIncrement = false;
40
+
41
+ /**
42
+ * Sets some basic model data
43
+ *
44
+ */
45
+ protected function _construct()
46
+ {
47
+ $this->_init('shipperhq_shipper/storage', 'quote_id');
48
+ }
49
+
50
+ /**
51
+ * Validate quote identifier
52
+ *
53
+ * @param Mage_Sales_Model_Quote $quote
54
+ * @return string
55
+ */
56
+ public function validateQuoteId($quote)
57
+ {
58
+ $select = $this->_getReadAdapter()->select();
59
+ $select->from($this->getTable('sales/quote'), 'entity_id')
60
+ ->where('entity_id = ?', $quote->getId());
61
+
62
+ return $this->_getReadAdapter()->fetchOne($select);
63
+ }
64
+
65
+ /**
66
+ * Decodes storage data after object has been saved
67
+ *
68
+ * @param Mage_Core_Model_Abstract $object
69
+ * @return $this
70
+ */
71
+ protected function _afterLoad(Mage_Core_Model_Abstract $object)
72
+ {
73
+ parent::_afterLoad($object);
74
+ $this->_decodeJsonData($object);
75
+ return $this;
76
+ }
77
+
78
+ /**
79
+ * Encodes storage data before save operation takes place
80
+ *
81
+ * @param Mage_Core_Model_Abstract $object
82
+ * @return $this
83
+ */
84
+ protected function _beforeSave(Mage_Core_Model_Abstract $object)
85
+ {
86
+ parent::_beforeSave($object);
87
+ $this->_encodeJsonData($object);
88
+ return $this;
89
+ }
90
+
91
+ /**
92
+ * Decodes storage data after save operation takes place
93
+ *
94
+ * @param Mage_Core_Model_Abstract $object
95
+ * @return $this
96
+ */
97
+ protected function _afterSave(Mage_Core_Model_Abstract $object)
98
+ {
99
+ parent::_afterSave($object);
100
+ $this->_decodeJsonData($object);
101
+ return $this;
102
+ }
103
+
104
+ /**
105
+ * Decodes JSON data and sets into object
106
+ *
107
+ * @param Mage_Core_Model_Abstract $object
108
+ * @return $this
109
+ */
110
+ protected function _decodeJsonData(Mage_Core_Model_Abstract $object)
111
+ {
112
+ if ($object->hasData('data')) {
113
+ $data = @json_decode($object->getData('data'), true);
114
+ if (is_array($data)) {
115
+ $data = $this->_filterJsonData($data);
116
+ $object->addData($data);
117
+ }
118
+
119
+ }
120
+
121
+ return $this;
122
+ }
123
+
124
+ /**
125
+ * Encodes JSON data from object and sets required database property
126
+ *
127
+ * @param Mage_Core_Model_Abstract $object
128
+ * @return $this
129
+ */
130
+ protected function _encodeJsonData(Mage_Core_Model_Abstract $object)
131
+ {
132
+ $data = $object->getData();
133
+ $data = $this->_filterJsonData($data);
134
+
135
+ foreach (array_keys($data) as $key) {
136
+ $object->unsetData($key);
137
+ }
138
+
139
+ $object->setData('data', json_encode($data));
140
+ return $this;
141
+ }
142
+
143
+ /**
144
+ * Filters JSON data from unexpected field values
145
+ *
146
+ * @param array $data
147
+ * @return array
148
+ */
149
+ protected function _filterJsonData(array $data)
150
+ {
151
+ if (isset($data[$this->getIdFieldName()])) {
152
+ unset($data[$this->getIdFieldName()]);
153
+ }
154
+
155
+ if (isset($data['data'])) {
156
+ unset($data['data']);
157
+ }
158
+
159
+ return $data;
160
+ }
161
+ }
app/code/community/Shipperhq/Shipper/Model/Sales/Quote/Address/Rate.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Shipping
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+
32
+ class Shipperhq_Shipper_Model_Sales_Quote_Address_Rate extends Mage_Sales_Model_Quote_Address_Rate
33
+ {
34
+
35
+ public function importShippingRate(Mage_Shipping_Model_Rate_Result_Abstract $rate)
36
+ {
37
+ if ($rate instanceof Mage_Shipping_Model_Rate_Result_Error) {
38
+ $this
39
+ ->setCode($rate->getCarrier().'_error')
40
+ ->setCarrier($rate->getCarrier())
41
+ ->setCarrierTitle($rate->getCarrierTitle())
42
+ ->setErrorMessage($rate->getErrorMessage())
43
+ ->setCarrierId($rate->getCarrierId())
44
+ ->setCarriergroupId($rate->getCarriergroupId())
45
+ ->setCarriergroup($rate->getCarriergroup())
46
+ ;
47
+ } elseif ($rate instanceof Mage_Shipping_Model_Rate_Result_Method) {
48
+ $this
49
+ ->setCode($rate->getCarrier().'_'.$rate->getMethod())
50
+ ->setCarrier($rate->getCarrier())
51
+ ->setCarrierTitle($rate->getCarrierTitle())
52
+ ->setMethod($rate->getMethod())
53
+ ->setMethodTitle($rate->getMethodTitle())
54
+ ->setMethodDescription($rate->getMethodDescription())
55
+ ->setPrice($rate->getPrice())
56
+ ->setCarriergroupId($rate->getCarriergroupId())
57
+ ->setCarriergroup($rate->getCarriergroup())
58
+ ->setCarrierType($rate->getCarrierType())
59
+ ->setDispatchDate($rate->getDispatchDate())
60
+ ->setDeliveryDate($rate->getDeliveryDate())
61
+ ->setCarriergroupShippingDetails($rate->getCarriergroupShippingDetails())
62
+ ->setCarrierNotice($rate->getCarrierNotice())
63
+ ->setFreightRate($rate->getFreightRate())
64
+ ->setCustomDescription($rate->getCustomDescription())
65
+ ->setCarrierId($rate->getCarrierId())
66
+ ->setCustomDuties($rate->getCustomDuties());
67
+
68
+ ;
69
+ }
70
+ return $this;
71
+ }
72
+
73
+ }
app/code/community/Shipperhq/Shipper/Model/Session.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Session extends Mage_Core_Model_Session_Abstract {
32
+
33
+ public function __construct() {
34
+ $namespace = 'shipperhq_shipper';
35
+ $namespace .= '_' . (Mage::app()->getStore()->getWebsite()->getCode());
36
+
37
+ $this->init($namespace);
38
+ Mage::dispatchEvent('shipperhq_shipper_session_init', array('shipperhq_shipper_session' => $this));
39
+ }
40
+
41
+ }
app/code/community/Shipperhq/Shipper/Model/Source/Freight/Freightclass.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Model_Source_Freight_Freightclass extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
32
+ {
33
+ public function toOptionArray()
34
+ {
35
+ $freight_class = array(
36
+ 50 => '50',
37
+ 55 => '55',
38
+ 60 => '60',
39
+ 65 => '65',
40
+ 70 => '70',
41
+ 77.5 => '77.5',
42
+ 85 => '85',
43
+ 92.5 => '92.5',
44
+ 100 => '100',
45
+ 110 => '110',
46
+ 125 => '125',
47
+ 150 => '150',
48
+ 175 => '175',
49
+ 200 => '200',
50
+ 250 => '250',
51
+ 300 => '300',
52
+ 400 => '400',
53
+ 500 => '500',
54
+ );
55
+
56
+ foreach ($freight_class as $k=>$v) {
57
+ $arr[] = array('value'=>$k, 'label'=>$v);
58
+ }
59
+
60
+ return $arr;
61
+ }
62
+ /**
63
+ * Retrieve All options
64
+ *
65
+ * @return array
66
+ */
67
+ public function getAllOptions()
68
+ {
69
+ $arr = $this->toOptionArray();
70
+ array_unshift($arr, array('value'=>'', 'label'=>Mage::helper('shipping')->__('--- Use Default ---')));
71
+ return $arr;
72
+ }
73
+ }
app/code/community/Shipperhq/Shipper/Model/Source/Validation/Result.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Core
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+ /**
27
+ *
28
+ * Webshopapps Shipping Module
29
+ *
30
+ * NOTICE OF LICENSE
31
+ *
32
+ * This source file is subject to the Open Software License (OSL 3.0)
33
+ * that is bundled with this package in the file LICENSE.txt.
34
+ * It is also available through the world-wide-web at this URL:
35
+ * http://opensource.org/licenses/osl-3.0.php
36
+ * If you did not receive a copy of the license and are unable to
37
+ * obtain it through the world-wide-web, please send an email
38
+ * to license@magentocommerce.com so we can send you a copy immediately.
39
+ *
40
+ * DISCLAIMER
41
+ *
42
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
43
+ * versions in the future. If you wish to customize Magento for your
44
+ * needs please refer to http://www.magentocommerce.com for more information.
45
+ *
46
+ * Shipper HQ Shipping
47
+ *
48
+ * @category ShipperHQ
49
+ * @package ShipperHQ_Shipping_Carrier
50
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
51
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
52
+ * @author ShipperHQ Team sales@shipperhq.com
53
+ */
54
+ class Shipperhq_Shipper_Model_Source_Validation_Result extends Mage_Core_Model_Abstract
55
+ {
56
+ const NOT_VALIDATED = 'UNCHECKED';
57
+ const VALID = 'EXACT_MATCH';
58
+ const VALID_CORRECTED = 'CORRECTED_EXACT_MATCH';
59
+ const AMBIGUOUS = 'NEAR_MATCH_WITH_OPTIONS';
60
+ const INVALID = 'INVALID';
61
+ const ERROR = 'ERROR';
62
+ const CUSTOMER_OVERRIDE = 'CUSTOMER_OVERRIDE';
63
+ const MANUAL_OVERRIDE = 'MANUAL_OVERRIDE';
64
+
65
+ const NOT_VALIDATED_PERCENTAGE = 'NOT_VALIDATED_PERCENTAGE';
66
+ const NOT_VALIDATED_NO_CARRIER = 'NOT_VALIDATED_NO_CARRIER';
67
+ const NOT_VALIDATED_DISABLED = 'NOT_VALIDATED_DISABLED';
68
+ const NOT_AUTHORIZED = 'NOT_AUTHORIZED';
69
+ const VALIDATION_NOT_ENABLED = 'VALIDATION_NOT_ENABLED';
70
+ const COUNTRY_NOT_SUPPORTED = 'COUNTRY_NOT_SUPPORTED';
71
+
72
+
73
+ protected $options;
74
+
75
+
76
+ public function getAllOptions()
77
+ {
78
+ if (!$this->options) {
79
+ $this->options = $this->toOptionArray();
80
+ }
81
+ return $this->options;
82
+ }
83
+
84
+ public function toOptionArray()
85
+ {
86
+ $possibleResults = array(
87
+ self::NOT_VALIDATED => self::NOT_VALIDATED,
88
+ self::VALID => self::VALID ,
89
+ self::AMBIGUOUS => self::AMBIGUOUS,
90
+ self::MANUAL_OVERRIDE => self::MANUAL_OVERRIDE,
91
+ self::CUSTOMER_OVERRIDE => self::CUSTOMER_OVERRIDE,
92
+ self::VALID_CORRECTED => self::VALID_CORRECTED,
93
+ self::INVALID => self::INVALID,
94
+ self::ERROR => self::ERROR
95
+
96
+ );
97
+
98
+ $arr = array();
99
+ foreach ($possibleResults as $k=>$v) {
100
+ $arr[] = array('value'=>$k, 'label'=>Mage::helper('shipperhq_shipper')->__($v));
101
+ }
102
+ return $arr;
103
+ }
104
+
105
+ }
app/code/community/Shipperhq/Shipper/Model/Storage.php ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ *
30
+ * Shipper Storage
31
+ */
32
+ class Shipperhq_Shipper_Model_Storage
33
+ extends Mage_Core_Model_Abstract
34
+ {
35
+ /**
36
+ * Quote object to which storage is attached
37
+ *
38
+ * @var Mage_Sales_Model_Quote
39
+ */
40
+ protected $_quote;
41
+
42
+ /**
43
+ * Stored addresses details
44
+ *
45
+ * @var Mage_Sales_Model_Quote_Address[]
46
+ */
47
+ protected $_storedAddresses = array();
48
+
49
+ /**
50
+ * Flag to indicate if storage has been loaded for quote
51
+ *
52
+ * @var bool
53
+ */
54
+ protected $_isLoaded = false;
55
+
56
+ /**
57
+ * Storage option
58
+ *
59
+ */
60
+ protected function _construct()
61
+ {
62
+ $this->_init('shipperhq_shipper/storage');
63
+ }
64
+
65
+ /**
66
+ * Loads data by quote object
67
+ *
68
+ * @param Mage_Sales_Model_Quote $quote
69
+ * @return $this
70
+ */
71
+ public function loadByQuote(Mage_Sales_Model_Quote $quote)
72
+ {
73
+ $this->_quote = $quote;
74
+ $this->_storedAddresses = array();
75
+
76
+ if ($quote->getId()) {
77
+ $this->load($quote->getId());
78
+ $this->_isLoaded = !$this->isEmpty();
79
+ $this->setId($quote->getId());
80
+ }
81
+
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * Returns true if object does not store any data except quote identifier
87
+ *
88
+ * @return bool
89
+ */
90
+ public function isEmpty()
91
+ {
92
+ return count(array_diff(array_keys($this->_data), array($this->getIdFieldName(), 'id'))) === 0;
93
+ }
94
+
95
+ /**
96
+ * Returns if storage object is still valid
97
+ * and has quote as not deleted
98
+ *
99
+ * @return bool
100
+ */
101
+ public function isValid($validateDatabase = false)
102
+ {
103
+ return $this->_quote !== null
104
+ && $this->_quote->isDeleted() === false
105
+ && $this->_quote->getId()
106
+ && (!$validateDatabase
107
+ || $this->_getResource()->validateQuoteId($this->_quote));
108
+ }
109
+
110
+ /**
111
+ * Returns is loaded flag
112
+ *
113
+ * @return bool
114
+ */
115
+ public function isLoaded()
116
+ {
117
+ return $this->_isLoaded;
118
+ }
119
+
120
+ /**
121
+ * Updates address list within a storage
122
+ *
123
+ * @return Mage_Core_Model_Abstract
124
+ */
125
+ protected function _beforeSave()
126
+ {
127
+ if ($this->_quote) {
128
+ $this->setId($this->_quote->getId());
129
+ }
130
+
131
+ foreach ($this->_storedAddresses as $addressHash => $address) {
132
+ if ($address->getId()) {
133
+ $this->setData(sprintf('address_%s', $address->getId()), $this->getDataForAddress($address));
134
+ }
135
+
136
+ $this->unsetData(sprintf('address_%s', $addressHash));
137
+ }
138
+
139
+ $this->_storedAddresses = array();
140
+ return parent::_beforeSave();
141
+ }
142
+
143
+
144
+ /**
145
+ * Overridden to support session like behavior with data clean up
146
+ *
147
+ * @param string $key
148
+ * @param null|bool $index
149
+ * @return mixed
150
+ */
151
+ public function getData($key = '', $index = null)
152
+ {
153
+ if ($index === true) {
154
+ $data = $this->getData($key);
155
+ $this->unsetData($key);
156
+ return $data;
157
+ }
158
+
159
+ return parent::getData($key, $index);
160
+ }
161
+
162
+ /**
163
+ * Sets a data for an address object
164
+ *
165
+ * @param Mage_Core_Model_Abstract $address
166
+ * @param string|array $key
167
+ * @param mixed|null $value
168
+ * @return $this
169
+ */
170
+ public function setDataForAddress(Mage_Core_Model_Abstract $address, $key, $value = null)
171
+ {
172
+ $this->_validateAddress($address);
173
+ $addressKey = $address->getId();
174
+
175
+ if ($addressKey === null) {
176
+ $addressKey = spl_object_hash($address);
177
+ $this->_storedAddresses[$addressKey] = $address;
178
+ }
179
+
180
+ if (is_array($key)) {
181
+ $this->setData(sprintf('address_%s', $addressKey), $key);
182
+ } else {
183
+ $data = $this->getDataForAddress($address);
184
+ $data[$key] = $value;
185
+ $this->setData(sprintf('address_%s', $addressKey), $key);
186
+ }
187
+
188
+ return $this;
189
+ }
190
+
191
+ /**
192
+ * Returns a data for address entity
193
+ *
194
+ * @param Mage_Core_Model_Abstract $address
195
+ * @param null|string $key
196
+ * @return array|mixed|null
197
+ */
198
+ public function getDataForAddress(Mage_Core_Model_Abstract $address, $key = null)
199
+ {
200
+ $this->_validateAddress($address);
201
+ $addressKey = $address->getId();
202
+
203
+ if ($addressKey === null) {
204
+ $addressKey = spl_object_hash($address);
205
+ if (!isset($this->_storedAddresses[$addressKey])) {
206
+ return array();
207
+ }
208
+ }
209
+
210
+ $data = $this->getData(sprintf('address_%s', $addressKey));
211
+ if (!is_array($data)) {
212
+ $data = array();
213
+ }
214
+
215
+ if ($key === null) {
216
+ return $data;
217
+ } elseif (isset($data[$key])) {
218
+ return $data[$key];
219
+ }
220
+
221
+ return null;
222
+ }
223
+
224
+ /**
225
+ * Validates address quote
226
+ *
227
+ * @param Mage_Core_Model_Abstract $address
228
+ * @return $this
229
+ */
230
+ protected function _validateAddress(Mage_Core_Model_Abstract $address)
231
+ {
232
+ if ($this->_quote === null) {
233
+ throw new RuntimeException('Quote object is not specified, cannot set address specific data');
234
+ }
235
+
236
+ if ($this->_quote !== $address->getQuote()) {
237
+ throw new RuntimeException('Quote object does not match address model');
238
+ }
239
+
240
+ return $this;
241
+ }
242
+ }
app/code/community/Shipperhq/Shipper/Model/Storage/Manager.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Storage manager
5
+ *
6
+ * Used to collect storage per quote
7
+ *
8
+ */
9
+ class Shipperhq_Shipper_Model_Storage_Manager
10
+ {
11
+ /**
12
+ * Storage by quote registry
13
+ *
14
+ * @var Shipperhq_Shipper_Model_Storage[]
15
+ */
16
+ protected $_storageByQuote = array();
17
+
18
+ /**
19
+ * Returns a storage by quote
20
+ *
21
+ * @param Mage_Sales_Model_Quote $quote
22
+ * @return Shipperhq_Shipper_Model_Storage
23
+ */
24
+ public function findByQuote(Mage_Sales_Model_Quote $quote)
25
+ {
26
+ $this->updateQuote($quote);
27
+
28
+ $key = $quote->getId();
29
+ if ($key === null) {
30
+ $key = spl_object_hash($quote);
31
+ }
32
+
33
+ if (!isset($this->_storageByQuote[$key])) {
34
+ $this->_storageByQuote[$key] = Mage::getModel('shipperhq_shipper/storage');
35
+ $this->_storageByQuote[$key]->loadByQuote($quote);
36
+ }
37
+
38
+ return $this->_storageByQuote[$key];
39
+ }
40
+
41
+ /**
42
+ * Returns list of all storage objects
43
+ *
44
+ * @return Shipperhq_Shipper_Model_Storage[]
45
+ */
46
+ public function getStorageObjects()
47
+ {
48
+ return array_values($this->_storageByQuote);
49
+ }
50
+
51
+ /**
52
+ * Updates storage by quote
53
+ *
54
+ * @param Mage_Sales_Model_Quote $quote
55
+ * @return $this
56
+ */
57
+ public function updateQuote(Mage_Sales_Model_Quote $quote)
58
+ {
59
+ if (isset($this->_storageByQuote[spl_object_hash($quote)]) && $quote->getId()) {
60
+ $this->_storageByQuote[$quote->getId()] = $this->_storageByQuote[spl_object_hash($quote)];
61
+ unset($this->_storageByQuote[spl_object_hash($quote)]);
62
+ $this->_storageByQuote[$quote->getId()]->setId($quote->getId());
63
+ }
64
+
65
+ return $this;
66
+ }
67
+ }
app/code/community/Shipperhq/Shipper/Model/Synchronize.php ADDED
@@ -0,0 +1,432 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ include_once 'ShipperHQ/WS/Client/WebServiceClient.php';
32
+ include_once 'ShipperHQ/WS/Response/ErrorMessages.php';
33
+
34
+ class Shipperhq_Shipper_Model_Synchronize extends Mage_Core_Model_Abstract
35
+ {
36
+
37
+ const ADD_ATTRIBUTE_OPTION = 'Add';
38
+ const REMOVE_ATTRIBUTE_OPTION = 'Manual delete required';
39
+ const AUTO_REMOVE_ATTRIBUTE_OPTION = 'Delete';
40
+ protected $_shipperWSInstance;
41
+ protected $_shipperMapperInstance;
42
+ protected $_prodAttributes;
43
+
44
+ /*
45
+ *Review latest attribute data and save changes required to database
46
+ */
47
+ public function updateSynchronizeData()
48
+ {
49
+ $latestAttributes = $this->_getLatestAttributeData();
50
+ $result = array();
51
+ if( $latestAttributes && array_key_exists('error', $latestAttributes)) {
52
+ $result['error'] = $latestAttributes['error'];
53
+ }
54
+ elseif($latestAttributes && !empty($latestAttributes)) {
55
+ $updateData = $this->_compareAttributeData($latestAttributes);
56
+ $result['result'] = $this->_saveSynchData($updateData);
57
+ }
58
+ else{
59
+ $result['error']
60
+ = Mage::getModel('shipperhq_shipper/carrier_shipper')->getCode('error', 1700);
61
+ }
62
+
63
+ return $result;
64
+
65
+ }
66
+
67
+ /*
68
+ *Get latest attribute data and perform changes required
69
+ */
70
+ public function synchronizeData()
71
+ {
72
+ $latestAttributes = $this->_getLatestAttributeData();
73
+ $result = array();
74
+ if( $latestAttributes && array_key_exists('error', $latestAttributes)) {
75
+ $result['error'] = $latestAttributes['error'];
76
+ }
77
+ elseif($latestAttributes && !empty($latestAttributes)) {
78
+ $updateData = $this->_compareAttributeData($latestAttributes);
79
+ $updateResult = $this->_updateAll($updateData);
80
+ $result['result'] = $updateResult;
81
+ }
82
+ else{
83
+ $result['error']
84
+ = Mage::getModel('shipperhq_shipper/carrier_shipper')->getCode('error', 1700);
85
+ }
86
+
87
+ return $result;
88
+ }
89
+
90
+ public function checkSynchStatus()
91
+ {
92
+ if(Mage::getStoreConfig('carriers/shipper/active')) {
93
+
94
+ $synchCheckUrl = Mage::helper('shipperhq_shipper')->getCheckSynchronizedUrl();
95
+ $timeout = Mage::helper('shipperhq_shipper')->getWebserviceTimeout();
96
+ $shipperMapper = $this->_getShipperMapper();
97
+ $request = $shipperMapper->getCredentialsTranslation();
98
+ $result = $this->_getShipperInstance()->sendAndReceive($request, $synchCheckUrl, $timeout);
99
+ $synchResult = $result['result'];
100
+ $debugData = array(
101
+ 'result' => json_decode($result['debug']['response']),
102
+ 'url' => $result['debug']['url']
103
+ );
104
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
105
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'Check synchronized status: ',
106
+ $debugData);
107
+ }
108
+ if(!empty($synchResult->errors)) {
109
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
110
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Shipper', 'Check synchronized status failed. Error: ',
111
+ $synchResult->errors);
112
+ }
113
+ return false;
114
+ }
115
+
116
+ if(!isset($synchResult->responseSummary) || $synchResult->responseSummary->status != 1) {
117
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
118
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Shipper', 'Check Synchronized Status failed with no error. ',
119
+ $synchResult);
120
+ }
121
+ return false;
122
+ }
123
+
124
+ $result = $synchResult->synchronized == 1 ? '1' : "Required";
125
+ return $result;
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Initialise shipper library class
131
+ *
132
+ * @return null|Shipper_Shipper
133
+ */
134
+ protected function _getShipperInstance()
135
+ {
136
+ if (empty($this->_shipperWSInstance)) {
137
+ $this->_shipperWSInstance = new \ShipperHQ\WS\Client\WebServiceClient();
138
+ }
139
+ return $this->_shipperWSInstance;
140
+ }
141
+
142
+ protected function _getShipperMapper()
143
+ {
144
+ if(empty($this->_shipperMapperInstance)) {
145
+ $this->_shipperMapperInstance = Mage::getSingleton('Shipperhq_Shipper_Model_Carrier_Convert_ShipperMapper');
146
+ }
147
+ return $this->_shipperMapperInstance;
148
+ }
149
+
150
+
151
+ protected function _getLatestAttributeData()
152
+ {
153
+ $result = array();
154
+ $synchronizeUrl = Mage::helper('shipperhq_shipper')->getAttributeGatewayUrl();
155
+ $timeout = Mage::helper('shipperhq_shipper')->getWebserviceTimeout();
156
+ $shipperMapper = $this->_getShipperMapper();
157
+ $request = $shipperMapper->getCredentialsTranslation();
158
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
159
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'Latest attributes request',
160
+ $request->siteDetails);
161
+ }
162
+ $resultSet = $this->_getShipperInstance()->sendAndReceive($request,$synchronizeUrl, $timeout);
163
+ $allAttributesResponse = $resultSet['result'];
164
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
165
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'Latest attributes response',
166
+ (array)$allAttributesResponse);
167
+ }
168
+ if(isset($allAttributesResponse->errors) && count($allAttributesResponse->errors) > 0) {
169
+ foreach($allAttributesResponse->errors as $errorDetails) {
170
+ $errorDetails = (array)$errorDetails;
171
+ if(array_key_exists('internalErrorMessage', $errorDetails)
172
+ && $errorDetails['internalErrorMessage'] != '') {
173
+ $result['error'] = $errorDetails['internalErrorMessage'];
174
+ }
175
+ else if(array_key_exists('externalErrorMessage', $errorDetails)
176
+ && $errorDetails['externalErrorMessage'] != '') {
177
+ $result['error'] = $errorDetails['externalErrorMessage'];
178
+ }
179
+ }
180
+ if(Mage::helper('shipperhq_shipper')->isDebug()) {
181
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Shipper HQ returned error', $allAttributesResponse->errors);
182
+ }
183
+ }
184
+
185
+ elseif (!$allAttributesResponse || !isset($allAttributesResponse->responseSummary) ||
186
+ (string)$allAttributesResponse->responseSummary->status != 1 ||
187
+ !$allAttributesResponse->attributeTypes ) {
188
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
189
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Unable to parse latest attributes response',
190
+ ': ' .$allAttributesResponse);
191
+ }
192
+ }
193
+ else {
194
+ $result = $allAttributesResponse->attributeTypes;
195
+ }
196
+ return $result;
197
+ }
198
+
199
+ protected function _compareAttributeData($latestAttributes)
200
+ {
201
+ $result = array();
202
+ $productAttributes = Mage::helper('shipperhq_shipper')->getProductAttributes();
203
+
204
+ foreach($latestAttributes as $attribute)
205
+ {
206
+ switch ($attribute->type) {
207
+ case 'product':
208
+ $productAttributeApi = Mage::getSingleton('catalog/product_attribute_api_v2');
209
+ try {
210
+ $existingAttributeOptions = array();
211
+ if(!in_array($attribute->code, $productAttributes)) {
212
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
213
+ Mage::helper('wsalogger/log')->postCritical('Shipperhq_Shipper',
214
+ 'Attribute '.$attribute->code .' does not exist.',
215
+ 'Verify you have latest version of ShipperHQ installed');
216
+ }
217
+ continue;
218
+ }
219
+ $existingAttributeInfo = $productAttributeApi->info($attribute->code);
220
+ if(is_array($existingAttributeInfo) && array_key_exists('options', $existingAttributeInfo)) {
221
+ $existingAttributeOptions = $existingAttributeInfo['options'];
222
+ }
223
+ }
224
+ catch (Exception $e) {
225
+ $e->getMessage();
226
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
227
+ Mage::helper('wsalogger/log')->postCritical('Shipperhq_Shipper',
228
+ 'Stopped Processing Synchronisation',
229
+ 'Unable to find attribute '.$attribute->code.' | Error: ' .$e->getMessage());
230
+ }
231
+ $result = false;
232
+ break;
233
+ }
234
+ $trackValues = $existingAttributeOptions;
235
+ foreach($attribute->attributes as $latestValue) {
236
+ $found = false;
237
+ foreach ($existingAttributeOptions as $key => $option) {
238
+ if ($option['label'] == $latestValue->name) {
239
+ $found = true;
240
+ unset($trackValues[$key]);
241
+ continue;
242
+ }
243
+ }
244
+
245
+ if(!$found) {
246
+ $result[] = array('attribute_type' => $attribute->type,
247
+ 'attribute_code' => $attribute->code,
248
+ 'value' => $latestValue->name,
249
+ // 'label' => $latestValue['description'];
250
+ 'status' => self::ADD_ATTRIBUTE_OPTION,
251
+ 'date_added' => date('Y-m-d H:i:s')
252
+
253
+ );
254
+ }
255
+
256
+ }
257
+ if(count($trackValues) > 0) {
258
+ //TODO add store selector in here
259
+ $storeId = '';
260
+ //AUTO_REMOVE_ATTRIBUTE_OPTION
261
+ foreach($trackValues as $key => $option) {
262
+ $numberAssigned = Mage::helper('shipperhq_shipper')->getProductsWithAttributeValue(
263
+ $attribute->code, $option['value'], $storeId, true, true);
264
+ $deleteFlag = self::AUTO_REMOVE_ATTRIBUTE_OPTION;
265
+ if($numberAssigned > 0) {
266
+ $deleteFlag = self::REMOVE_ATTRIBUTE_OPTION;
267
+ }
268
+
269
+ $result[] = array('attribute_type' => $attribute->type,
270
+ 'attribute_code' => $attribute->code,
271
+ 'value' => $option['label'],
272
+ 'option_id' => $option['value'],
273
+ 'status' => $deleteFlag,
274
+ 'date_added' => date('Y-m-d H:i:s')
275
+ );
276
+ }
277
+ }
278
+ break;
279
+ case 'global':
280
+ if($attribute->code == 'global_settings') {
281
+ foreach($attribute->attributes as $globalSetting) {
282
+ $value = $globalSetting->value == 'true'? 1: 0;
283
+ if(Mage::getStoreConfig('carriers/shipper/'.$globalSetting->code) != $value) {
284
+ $result[] = array('attribute_type' => 'global_setting',
285
+ 'attribute_code' => $globalSetting->code,
286
+ 'value' => $value,
287
+ 'option_id' => '',
288
+ 'status' => self::ADD_ATTRIBUTE_OPTION,
289
+ 'date_added' => date('Y-m-d H:i:s')
290
+ );
291
+ }
292
+ }
293
+ }
294
+ case 'customer':
295
+ //compare customer groups
296
+ break;
297
+ default :
298
+ break;
299
+ }
300
+
301
+ }
302
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
303
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'Compare attributes result: ', $result);
304
+ }
305
+
306
+ return $result;
307
+ }
308
+
309
+ /**
310
+ * Checks to see if we have been sent extra info we want on the attribute
311
+ *
312
+ * @param $name
313
+ * @param $value
314
+ */
315
+ protected function _extraInfoContains($extraInfoList, $keyToMatch, $valueToMatch) {
316
+ foreach($extraInfoList as $extraInfo) {
317
+ if ($extraInfo->key==$keyToMatch && $extraInfo->value==$valueToMatch) {
318
+ return true;
319
+ }
320
+ }
321
+ return false;
322
+ }
323
+
324
+
325
+ protected function _saveSynchData($data)
326
+ {
327
+ $result = 0;
328
+ //remove all existing rows
329
+ try{
330
+ foreach($collection = Mage::getModel('shipperhq_shipper/attributeupdate')->getCollection() as $oldUpdate)
331
+ {
332
+ $oldUpdate->delete();
333
+ }
334
+ }
335
+ catch (Exception $e) {
336
+ $result = false;
337
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
338
+ Mage::helper('wsalogger/log')->postWarning('Shipperhq_Shipper',
339
+ 'Unable to remove existing attribute update data', $e->getMessage());
340
+ }
341
+ }
342
+ if(empty($data)) {
343
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
344
+ Mage::helper('wsalogger/log')->postDebug('Shipperhq_Shipper', 'Saving synch data',
345
+ 'No attribute changes required, 0 rows saved');
346
+ }
347
+ return $result;
348
+ }
349
+
350
+ foreach($data as $update)
351
+ {
352
+ $newUpdate = Mage::getModel('shipperhq_shipper/attributeupdate');
353
+ $newUpdate->setData($update);
354
+ $newUpdate->save();
355
+ $newUpdate->clearInstance();
356
+ $result++;
357
+ }
358
+ return $result;
359
+
360
+ }
361
+
362
+ /*
363
+ * Add new option values to attributes
364
+ *
365
+ */
366
+ protected function _updateAll($updateData)
367
+ {
368
+ $result = 0;
369
+ $productAttributeApi = Mage::getSingleton('catalog/product_attribute_api_v2');
370
+
371
+ foreach($updateData as $attributeUpdate)
372
+ {
373
+ if($attributeUpdate['attribute_type'] == 'product') {
374
+ if($attributeUpdate['status'] == self::ADD_ATTRIBUTE_OPTION) {
375
+ $optionToAdd = array(
376
+ 'label' => array(
377
+ array (
378
+ 'store_id' => 0,
379
+ 'value' => $attributeUpdate['value']
380
+ )
381
+
382
+ ),
383
+ 'order' => 0,
384
+ 'is_default' => 0
385
+ );
386
+ try {
387
+ $productAttributeApi->addOption($attributeUpdate['attribute_code'], $optionToAdd);
388
+ $result++;
389
+ }
390
+ catch (Exception $e){
391
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
392
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Unable to add attribute option',
393
+ 'Error: ' .$e->getMessage());
394
+ }
395
+ $result = false;
396
+ }
397
+ }
398
+ else if($attributeUpdate['status'] == self::AUTO_REMOVE_ATTRIBUTE_OPTION) {
399
+ try {
400
+ $productAttributeApi->removeOption($attributeUpdate['attribute_code'], $attributeUpdate['option_id']);
401
+ $result++;
402
+ }
403
+ catch (Exception $e) {
404
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
405
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Unable to remove attribute option',
406
+ 'Error: ' .$e->getMessage());
407
+ }
408
+ $result = false;
409
+ }
410
+ }
411
+ }
412
+ elseif($attributeUpdate['attribute_type'] == 'global_setting') {
413
+ Mage::helper('shipperhq_shipper')->saveConfig('carriers/shipper/'.$attributeUpdate['attribute_code'],
414
+ $attributeUpdate['value']);
415
+ }
416
+ }
417
+
418
+
419
+ if ($result >= 0) {
420
+ $synchSetUrl = Mage::helper('shipperhq_shipper')->getSetSynchronizedUrl();
421
+ $timeout = Mage::helper('shipperhq_shipper')->getWebserviceTimeout();
422
+ $shipperMapper = $this->_getShipperMapper();
423
+ $request = $shipperMapper->getCredentialsTranslation();
424
+ $setSynchResult = $this->_getShipperInstance()->sendAndReceive($request, $synchSetUrl, $timeout);
425
+ if (Mage::helper('shipperhq_shipper')->isDebug()) {
426
+ Mage::helper('wsalogger/log')->postInfo('Shipperhq_Shipper', 'Setting synchronized status: ',
427
+ $setSynchResult['result']);
428
+ }
429
+ }
430
+ return $result;
431
+ }
432
+ }
app/code/community/Shipperhq/Shipper/changelog.txt ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1.0 - Initial release
2
+ 1.1 - Integration update
3
+ 1.1 - Release Candidate
4
+ 1.2 - Release candidate update
5
+ 1.3 - Release
6
+ 1.4 - Release Candidate
7
+ 1.5 - Pickup preselect in multi address checkout
8
+ 1.6 - SHIPPERHQ-441 - Calendar display issues resolved
9
+ 1.7 - SHIPPERHQ-466 - Ajax modifications on calendar templates, SHIPPERHQ-415 UK Date Support
10
+ 1.8 - SHIPPERHQ-318 - carrier code support, SHIPPERHQ-486 - Discounted item logic
11
+ 1.9 - CHEF-108 - Rate request modifications
12
+ 1.10 - CHEF-108 - Removed FreeMethodWeight from request
13
+ 1.11 - CHEF-110 - Resolved duplicated date in MAC for calendar based rates
14
+ 1.12 - SHIPPERHQ-531 - rerequest rates for Pickup carriers to retrieve correct time slots
15
+ SHIPPERHQ-507 - added appVersion to the request
16
+ 1.13 - SHIPPERHQ-566 - defaults match Dashboard defaults
17
+ 1.14 - SHIPPERHQ-577 - Set up default account that will work when the extension is installed
18
+ 1.15 - SHIPPERHQ-605 - add ship_box_tolerance attribute and updated some shipperhq attributes to store scope
19
+ 1.16 - SHIPPERHQ-641 - added template helper to check for SHQ enabled and return default template if not enabled
20
+ SHIPPERHQ-640 - added check for ShipperHQ carrier enabled before attempting to retrieve carriers on config save
21
+ SHIPPERHQ-632 - ship separately dependent on rule group not set
22
+ 1.17 - SHIPPERHQ-669 - template helper for OSC files. Removed erroneous log messages
23
+
24
+ 1.18 - SHIPPERHQ-611 - Display date selector by default for single calendar carrier in OPC
25
+ 1.19 - SHIPPERHQ-764 - implemented currency conversion. DRY changes, SHIPPERHQ-801 - resolve template if statement for pickup rates, SHIPPERHQ-747 - removed free shipping product attribute, SHIPPERHQ-669 - template helper for OSC files. Removed erroneous log messages, SHIPPERHQ-801 - resolve template if statement for pickup rates, SHIPPERHQ-609 - assign carriergroup id to all items and check for display merged on MA checkout, SHIPPERHQ-782 - Adapted processing for merged rate response
26
+ 1.20 - SHIPPERHQ-632 - dynamic configuration option display for dimensional attributes
27
+ 1.21 - SHIPPERHQ-831 - City field mandatory when autocomplete enabled
28
+ 1.22 - SHIPPERHQ-743 - ignore date formatting when comparing date strings
29
+ 1.23 - SHIPPERHQ-660 pickup elements hidden for updated rates, pickup elements listener for updated rates on checkout and save shipping method on admin order submit
30
+ 1.24 - SHIPPERHQ-889 - removed re-request of rates on OSC submit
31
+ 1.25 - SHIPPERHQ-659 default date support
32
+ 1.26 - SHIPPERHQ-931 Calendar admin order observer config, SHIPPERHQ-911 sort order on carriers
33
+ 1.27 - SHIPPERHQ-968 city required on cart
34
+ 1.28 - SHIPPERHQ-937 - removed delivery date string from shipping description, SHIPPERHQ-968 removed city enabled in cart for specific client, SHIPPERHQ-969 - registered shipment items when shipping
35
+ 1.29 - SHIPPERHQ-1042 - save default values for display from cart to checkout and on save shipping method, SHIPPERHQ-1041 - accessorial display cache corrected, SHIPPERHQ-1042 - display of selected on admin and customer account, SHIPPERHQ-1041 - accessorial display cache corrected
36
+ 1.30 - SHIPPERHQ-1058 Tagging here as not sure on status
37
+ 1.31 - SHIPPERHQ-1066 - resolved display of acc on 1.9 cart
38
+ 1.32 - SHIPPERHQ-1106 - sort by price
39
+ 1.34 - SHIPPERHQ-973, SHIPPERHQ-1165 - display updates
40
+ 1.38 - SHIPPERHQ-1101 - configurable item weight display
41
+ 1.41 - SHIPPERHQ-1184 - PayPal Express shipping method display patch
42
+ 1.46 - SHIPPERHQ-1205 - installation script modifications
43
+ 1.50 - SHIPPERHQ-1268, SHIPPERHQ-1269 - installation script modifications
44
+ 1.57 - SHIPPERHQ-1258, SHIPPERHQ-1315, SHIPPERHQ-1289 - optional caching of rates, modified attribute seperator in request
45
+ 1.58 - SHIPPERHQ-1339 - Freight accessorial changes
46
+ 1.63 - SHIPPERHQ-1424 - moved attribute source to base module
47
+ 1.64 - SHIPPERHQ-1460 - move carriergroup logic, SHIPPERHQ-1373 Pitney and GSO support
48
+ 1.65 - SHIPPERHQ-1442 - store specific credentials
49
+ 2.0 - PITNEY-5 - modified request for new address fields
50
+ 2.3 - SHIPPERHQ-1508 - display selected dates and time at checkout for review
51
+ 2.4 - SHIPPERHQ-1556 - Address validation dialog correction on shipping address
52
+ 2.7 - SHIPPERHQ-1616 - correct filtering for store id in orders grid
53
+ 2.10 - SHIPPERHQ-1630 - Freight accessorials support for split, SHIPPERHQ-1639 - Merged function logic in templates
54
+ 2.12 - SHIPPERHQ-1628 - Accessorial defaults in cart
55
+ 2.15 - SHIPPERHQ-1631 - Destination type support on address validation
56
+ 2.18 - SHIPPERHQ-1701 - OSC pre selected show elements
57
+ 2.20 - SHIPPERHQ-1710, SHIPPERHQ-1709 - OSC support changes, SHIPPERHQ-1689 include virtual items in cart
58
+ 2.21 - SHIPPERHQ-1717 Bundle parent carriergroup ID
59
+ 2.22 - SHIPPERHQ-1721 Support for security patch SUPEE-6788
60
+ 2.23 - SHIPPERHQ-1716 city field enabled via config, SHIPPERHQ-1731 freight accessorials defaults not being used
61
+ 2.25 - SHIPPERHQ-1556 support split custom admin shipping and added address type to request as lower case, PITNEY-14 additional logging
62
+ 2.27 - SHIPPERHQ-1765 custom rate description implemented
63
+ 2.28 - SHIPPERHQ-1765 amend custom rate description implementation, SHIPPERHQ-1326 date support for en-GB locale
64
+ 2.30 - SHIPPERHQ-1808 removed dimensions from dimensional rule group restrictions
65
+ 2.31 - PITNEY-16 Amended product catalog upload logic
66
+ 2.32 - SHIPPERHQ-1823 address validation results on existing addresses, PITNEY-17 - amended order of tax totals
67
+ 2.33 - SHIPPERHQ-1826 Shipping detail display for multi address orders
68
+ 2.34 - SHIPPERHQ-1842 Master packing boxes support, SHIPPERHQ-1862 time slot on order email, SHIPPERHQ-1863 MAC bundle gift options support
69
+ 2.39 - SHQ16-208 - Rate caching amendments, SHIPPERHQ-1899 amended city required in cart
70
+ 2.44 - SHQ16-142 - Extended migration tool
71
+ 2.46 - SHQ16-477 Freight migrate values from legacy freight extensions
72
+ 2.47 - SHQ16-503 - Custom admin shipping support for free shipping
73
+ 2.48 - SHQ16-169 - Record delivery date formatted against shipping address
74
+ 2.49 - SHQ16-477 further migrations for freight legacy extensions
75
+ 2.50 - SHQ16-538 OSC support for v4.0.9
76
+ 2.51 - SHQ16-488 Accessorial support in admin
77
+ 2.53 - SHQ16-598 Shipment packages created specific to shipping rates
78
+
79
+
80
+
81
+
82
+
app/code/community/Shipperhq/Shipper/controllers/Adminhtml/ShqajaxController.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Adminhtml_ShqajaxController extends Mage_Adminhtml_Controller_Action
32
+ {
33
+
34
+
35
+ public function refreshcarriersAction()
36
+ {
37
+ $carrier = Mage::getModel('shipperhq_shipper/carrier_shipper');
38
+ $refreshResult = $carrier->refreshCarriers();
39
+ $success = 1;
40
+ $session = Mage::getSingleton('Mage_Adminhtml_Model_Session');
41
+ $session->getMessages(true);
42
+ if (array_key_exists('error', $refreshResult)) {
43
+ $message = $refreshResult['error'];
44
+ $session->addError($message);
45
+ $success = 0;
46
+ }
47
+ elseif(array_key_exists('warning', $refreshResult)) {
48
+ $message = $refreshResult['warning'];
49
+ $session->addSuccess($message);
50
+ $success = 2;
51
+ }
52
+ else {
53
+ $message = Mage::helper('shipperhq_shipper')->__('%s shipping methods have been updated from ShipperHQ', count($refreshResult));
54
+ $session->addSuccess($message);
55
+ }
56
+
57
+ $this->_initLayoutMessages('adminhtml/session');
58
+ $session_messages = $this->getLayout()->getMessagesBlock()->getGroupedHtml();
59
+
60
+ $result= array('result' =>$success, 'message' =>$message, 'session_messages' => $session_messages);
61
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
62
+ }
63
+ }
app/code/community/Shipperhq/Shipper/controllers/Adminhtml/ShqsynchronizeController.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Webshopapps Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * Shipper HQ Shipping
23
+ *
24
+ * @category ShipperHQ
25
+ * @package ShipperHQ_Shipping_Carrier
26
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
27
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28
+ * @author ShipperHQ Team sales@shipperhq.com
29
+ */
30
+
31
+ class Shipperhq_Shipper_Adminhtml_ShqsynchronizeController extends Mage_Adminhtml_Controller_Action
32
+ {
33
+ protected function _initAction()
34
+ {
35
+ $this->loadLayout()
36
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Synchronize with ShipperHQ'), Mage::helper('adminhtml')->__('Synchronize with ShipperHQ'));
37
+ return $this;
38
+ }
39
+
40
+ public function indexAction()
41
+ {
42
+ $result = Mage::getModel('shipperhq_shipper/synchronize')->updateSynchronizeData();
43
+ if (array_key_exists('error', $result)) {
44
+ $session = Mage::getSingleton('Mage_Adminhtml_Model_Session');
45
+ $message = Mage::helper('shipperhq_shipper')->__($result['error']);
46
+ $session->addError($message);
47
+
48
+ } else {
49
+ $session = Mage::getSingleton('Mage_Adminhtml_Model_Session');
50
+ if ($result['result'] == 0) {
51
+ $message = Mage::helper('shipperhq_shipper')->__('Received latest attribute values from ShipperHQ, no changes are required.');
52
+ $session->addSuccess($message);
53
+ } else {
54
+ $message = Mage::helper('shipperhq_shipper')->__('Received latest attribute values from ShipperHQ, %s changes required. Ready to synchronize', $result['result']);
55
+ $session->addSuccess($message);
56
+ }
57
+
58
+
59
+ }
60
+
61
+ $this->_initAction()
62
+ ->renderLayout();
63
+ }
64
+
65
+ public function refreshAction()
66
+ {
67
+ $this->_redirect('*/*/index');
68
+ }
69
+
70
+ public function synchronizeAction()
71
+ {
72
+ $result = Mage::getModel('shipperhq_shipper/synchronize')->synchronizeData();
73
+ if (empty($result)) {
74
+ $session = Mage::getSingleton('Mage_Adminhtml_Model_Session');
75
+ $message = Mage::helper('shipperhq_shipper')->__('ShipperHQ was unable to verify a connection, please contact support.');
76
+ $session->addError($message);
77
+ }
78
+ else if (array_key_exists('error',$result)) {
79
+ $session = Mage::getSingleton('Mage_Adminhtml_Model_Session');
80
+ $message = $result['error'];
81
+ $session->addError($message);
82
+ }
83
+ else if ($result != 0) {
84
+ $message = Mage::helper('shipperhq_shipper')->__('Updated %s attribute values from ShipperHQ.', $result['result']);
85
+ $session = Mage::getSingleton('Mage_Adminhtml_Model_Session');
86
+ $session->addSuccess($message);
87
+ }
88
+
89
+ $this->_redirect('*/*/index');
90
+ }
91
+
92
+ protected function _isAllowed()
93
+ {
94
+ return Mage::getSingleton('admin/session')->isAllowed('catalog/shipperhq');
95
+ }
96
+ }
app/code/community/Shipperhq/Shipper/etc/adminhtml.xml ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Shipping
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ -->
32
+ <config>
33
+ <acl>
34
+ <resources>
35
+ <admin>
36
+ <children>
37
+ <catalog>
38
+ <children>
39
+ <shipperhq translate="title" module="shipperhq_shipper">
40
+ <title>ShipperHQ</title>
41
+ <children>
42
+ <synchronize translate="title" module="shipperhq_shipper">
43
+ <title>Synchronize ShipperHQ</title>
44
+ </synchronize>
45
+ </children>
46
+ </shipperhq>
47
+ </children>
48
+ </catalog>
49
+ </children>
50
+ </admin>
51
+ </resources>
52
+ </acl>
53
+ <menu>
54
+ <catalog>
55
+ <children>
56
+ <shipperhq translate="title" module="shipperhq_shipper">
57
+ <title>ShipperHQ</title>
58
+ <sort_order>15</sort_order>
59
+ <children>
60
+ <synchronize translate="title" module="shipperhq_shipper">
61
+ <title>Synchronize ShipperHQ</title>
62
+ <action>adminhtml/shqsynchronize</action>
63
+ <sort_order>11</sort_order>
64
+ </synchronize>
65
+ </children>
66
+ </shipperhq>
67
+ </children>
68
+ </catalog>
69
+ </menu>
70
+ </config>
app/code/community/Shipperhq/Shipper/etc/config.xml ADDED
@@ -0,0 +1,523 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!--
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Shipping
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ -->
32
+ <config>
33
+ <modules>
34
+ <Shipperhq_Shipper>
35
+ <version>0.0.30</version>
36
+ <extension_version>2.52</extension_version>
37
+ <!-- implemented in module file -->
38
+ <!-- <active>true</active>
39
+ <codePool>community</codePool>
40
+ <depends>
41
+ <Mage_Shipping/>
42
+ </depends> -->
43
+ </Shipperhq_Shipper>
44
+ </modules>
45
+ <admin>
46
+ <routers>
47
+ <adminhtml>
48
+ <args>
49
+ <modules>
50
+ <Shipperhq_Shipper after="Mage_Adminhtml">Shipperhq_Shipper_Adminhtml</Shipperhq_Shipper>
51
+ </modules>
52
+ </args>
53
+ </adminhtml>
54
+ </routers>
55
+ </admin>
56
+ <global>
57
+ <blocks>
58
+ <shipperhq_shipper>
59
+ <class>Shipperhq_Shipper_Block</class>
60
+ </shipperhq_shipper>
61
+ </blocks>
62
+ <helpers>
63
+ <shipperhq_shipper>
64
+ <class>Shipperhq_Shipper_Helper</class>
65
+ </shipperhq_shipper>
66
+ </helpers>
67
+ <models>
68
+ <shipperhq_shipper>
69
+ <class>Shipperhq_Shipper_Model</class>
70
+ <resourceModel>shipperhq_shipper_resource</resourceModel>
71
+ </shipperhq_shipper>
72
+ <shipperhq_shipper_resource>
73
+ <class>Shipperhq_Shipper_Model_Resource</class>
74
+ <entities>
75
+ <attributeupdate>
76
+ <table>shipperhq_synchronize</table>
77
+ </attributeupdate>
78
+ <storage>
79
+ <table>shipperhq_storage</table>
80
+ </storage>
81
+ <quote_packages>
82
+ <table>shipperhq_quote_packages</table>
83
+ </quote_packages>
84
+ <quote_package_items>
85
+ <table>shipperhq_quote_package_items</table>
86
+ </quote_package_items>
87
+ <order_packages>
88
+ <table>shipperhq_order_packages</table>
89
+ </order_packages>
90
+ <order_package_items>
91
+ <table>shipperhq_order_package_items</table>
92
+ </order_package_items>
93
+ </entities>
94
+ </shipperhq_shipper_resource>
95
+ <sales>
96
+ <rewrite>
97
+ <quote_address_rate>Shipperhq_Shipper_Model_Sales_Quote_Address_Rate</quote_address_rate>
98
+ </rewrite>
99
+ </sales>
100
+ </models>
101
+ <resources>
102
+ <shipperhq_shipper_setup>
103
+ <setup>
104
+ <module>Shipperhq_Shipper</module>
105
+ <class>Mage_Eav_Model_Entity_Setup</class>
106
+ </setup>
107
+ </shipperhq_shipper_setup>
108
+ </resources>
109
+ <events>
110
+ <!--method title synchronize with ShipperHQ -->
111
+ <admin_system_config_changed_section_carriers>
112
+ <observers>
113
+ <shipperhq_shipper_observer>
114
+ <class>Shipperhq_Shipper_Model_Observer</class>
115
+ <method>updateTitles</method>
116
+ </shipperhq_shipper_observer>
117
+ </observers>
118
+ </admin_system_config_changed_section_carriers>
119
+ <!-- set renderer for dimensional elements -->
120
+ <adminhtml_catalog_product_edit_prepare_form>
121
+ <observers>
122
+ <shipperhq_shipper_observer>
123
+ <class>Shipperhq_Shipper_Model_Observer</class>
124
+ <method>catalogProductEditSetRenderer</method>
125
+ </shipperhq_shipper_observer>
126
+ </observers>
127
+ </adminhtml_catalog_product_edit_prepare_form>
128
+ <!-- add dependency for dimensional fields on product edit -->
129
+ <catalog_product_edit_form_render_packingboxes>
130
+ <observers>
131
+ <shipperhq_shipper_observer>
132
+ <class>Shipperhq_Shipper_Model_Observer</class>
133
+ <method>prepareProductEditFormDimensional</method>
134
+ </shipperhq_shipper_observer>
135
+ </observers>
136
+ </catalog_product_edit_form_render_packingboxes>
137
+ <!-- check cart display items required -->
138
+ <core_block_abstract_to_html_before>
139
+ <observers>
140
+ <shipperhq_shipper_cart_estimate_display>
141
+ <class>shipperhq_shipper/observer</class>
142
+ <method>checkCartDisplayRequired</method>
143
+ </shipperhq_shipper_cart_estimate_display>
144
+ </observers>
145
+ </core_block_abstract_to_html_before>
146
+ <!-- set checkout flag for rates processing -->
147
+ <controller_action_predispatch_checkout_onepage_saveBilling>
148
+ <observers>
149
+ <shipperhq_shipper_savebilling_observer>
150
+ <class>shipperhq_shipper/observer</class>
151
+ <method>onCheckoutSaveBilling</method>
152
+ </shipperhq_shipper_savebilling_observer>
153
+ </observers>
154
+ </controller_action_predispatch_checkout_onepage_saveBilling>
155
+ <!-- set checkout for rates processing and re-request rates if it's split checkout -->
156
+ <controller_action_predispatch_onestepcheckout_index_index>
157
+ <observers>
158
+ <shipperhq_shipper_onestepcheckout_predispatch_observer>
159
+ <class>shipperhq_shipper/observer</class>
160
+ <method>onOneStepCheckoutIndex</method>
161
+ </shipperhq_shipper_onestepcheckout_predispatch_observer>
162
+ </observers>
163
+ </controller_action_predispatch_onestepcheckout_index_index>
164
+ <!-- set cart flag for rate request -->
165
+ <controller_action_predispatch_checkout_cart_estimatePost>
166
+ <observers>
167
+ <shipperhq_shipper_estimatepost_observer>
168
+ <class>shipperhq_shipper/observer</class>
169
+ <method>onCheckoutCartEstimatePost</method>
170
+ </shipperhq_shipper_estimatepost_observer>
171
+ </observers>
172
+ </controller_action_predispatch_checkout_cart_estimatePost>
173
+ <!-- set cart flag for rate request -->
174
+ <controller_action_predispatch_checkout_cart_index>
175
+ <observers>
176
+ <shipperhq_shipper_estimatepost_observer>
177
+ <class>shipperhq_shipper/observer</class>
178
+ <method>onCheckoutCartEstimatePost</method>
179
+ </shipperhq_shipper_estimatepost_observer>
180
+ </observers>
181
+ </controller_action_predispatch_checkout_cart_index>
182
+ <!--set cart flag for rate request -->
183
+ <checkout_type_multishipping_set_shipping_items>
184
+ <observers>
185
+ <shipperhq_shipper_multishipping_observer>
186
+ <class>shipperhq_shipper/observer</class>
187
+ <method>multiCheckoutShippingPredispatch</method>
188
+ </shipperhq_shipper_multishipping_observer>
189
+ </observers>
190
+ </checkout_type_multishipping_set_shipping_items>
191
+ <!-- initialize storage on quote after load -->
192
+ <sales_quote_load_after>
193
+ <observers>
194
+ <shipperhq_shipper_observer>
195
+ <class>shipperhq_shipper/observer</class>
196
+ <method>onQuoteAfterLoad</method>
197
+ </shipperhq_shipper_observer>
198
+ </observers>
199
+ </sales_quote_load_after>
200
+ <!-- saves storage on quote after save -->
201
+ <sales_quote_save_after>
202
+ <observers>
203
+ <shipperhq_shipper_observer>
204
+ <class>shipperhq_shipper/observer</class>
205
+ <method>onQuoteAfterSave</method>
206
+ </shipperhq_shipper_observer>
207
+ </observers>
208
+ </sales_quote_save_after>
209
+ <!-- saves unsaved storage objects -->
210
+ <controller_action_postdispatch>
211
+ <observers>
212
+ <shipperhq_shipper_observer>
213
+ <class>shipperhq_shipper/observer</class>
214
+ <method>onPostDispatch</method>
215
+ </shipperhq_shipper_observer>
216
+ </observers>
217
+ </controller_action_postdispatch>
218
+ <create_order_session_quote_initialized>
219
+ <observers>
220
+ <shipperhq_shipper_observer>
221
+ <class>shipperhq_shipper/observer</class>
222
+ <method>setCurrentQuoteObjectInAdmin</method>
223
+ </shipperhq_shipper_observer>
224
+ </observers>
225
+ </create_order_session_quote_initialized>
226
+ <adminhtml_sales_order_create_process_data_before>
227
+ <observers>
228
+ <shipperhq_shipper_observer>
229
+ <class>shipperhq_shipper/observer</class>
230
+ <method>setCurrentQuoteObjectInAdminFromSaveData</method>
231
+ </shipperhq_shipper_observer>
232
+ </observers>
233
+ </adminhtml_sales_order_create_process_data_before>
234
+ <sales_order_place_after>
235
+ <observers>
236
+ <shipperhq_shipper_placeorder_observer>
237
+ <class>shipperhq_shipper/observer</class>
238
+ <method>saveOrderAfter</method>
239
+ </shipperhq_shipper_placeorder_observer>
240
+ </observers>
241
+ </sales_order_place_after>
242
+ <!--admin shipper observer -->
243
+ <adminhtml_sales_order_create_process_data_before>
244
+ <observers>
245
+ <shipperhq_shipper_admin_create_order>
246
+ <class>shipperhq_shipper/observer</class>
247
+ <method>adminSalesOrderCreateProcessDataBefore</method>
248
+ </shipperhq_shipper_admin_create_order>
249
+ </observers>
250
+ </adminhtml_sales_order_create_process_data_before>
251
+ <!--save shipping details and reserve order process OPC-->
252
+ <checkout_controller_onepage_save_shipping_method>
253
+ <observers>
254
+ <shipperhq_shipper_save_shipping_method>
255
+ <type>model</type>
256
+ <class>shipperhq_shipper/observer_order</class>
257
+ <method>saveShippingMethod</method>
258
+ </shipperhq_shipper_save_shipping_method>
259
+ </observers>
260
+ </checkout_controller_onepage_save_shipping_method>
261
+ <!--save shipping details and reserve order process MAC -->
262
+ <checkout_controller_multishipping_shipping_post>
263
+ <observers>
264
+ <shipperhq_shipper_save_shipping_method_multi>
265
+ <type>singleton</type>
266
+ <class>shipperhq_shipper/observer_order</class>
267
+ <method>saveShippingMethodMulti</method>
268
+ </shipperhq_shipper_save_shipping_method_multi>
269
+ </observers>
270
+ </checkout_controller_multishipping_shipping_post>
271
+ <!--save shipping details and reserve order process OSC -->
272
+ <controller_action_predispatch_onestepcheckout_ajax_set_methods_separate>
273
+ <observers>
274
+ <shipperhq_shipper_onestepcheckout_ajax_setmethodsseparate>
275
+ <class>shipperhq_shipper/observer_order</class>
276
+ <method>preDispatchSetMethodsSeparate</method>
277
+ </shipperhq_shipper_onestepcheckout_ajax_setmethodsseparate>
278
+ </observers>
279
+ </controller_action_predispatch_onestepcheckout_ajax_set_methods_separate>
280
+ <!--save shipping details and reserve order process ADMIN -->
281
+ <adminhtml_sales_order_create_process_data_before>
282
+ <observers>
283
+ <shipperhq_shipper_save_shipping_methods_observer>
284
+ <class>shipperhq_shipper/observer_order</class>
285
+ <method>saveShippingMethodAdmin</method>
286
+ </shipperhq_shipper_save_shipping_methods_observer>
287
+ </observers>
288
+ </adminhtml_sales_order_create_process_data_before>
289
+ <!-- confirm order processing OPC-->
290
+ <checkout_onepage_controller_success_action>
291
+ <observers>
292
+ <shipperhq_shipper_onpage_success>
293
+ <type>model</type>
294
+ <class>shipperhq_shipper/observer_order</class>
295
+ <method>checkoutOnepageSuccess</method>
296
+ </shipperhq_shipper_onpage_success>
297
+ </observers>
298
+ </checkout_onepage_controller_success_action>
299
+ <!-- confirm order processing MAC -->
300
+ <checkout_multishipping_controller_success_action>
301
+ <observers>
302
+ <shipperhq_shipper_multiaddress_success>
303
+ <class>shipperhq_shipper/observer_order</class>
304
+ <method>checkoutMulitaddressSuccess</method>
305
+ </shipperhq_shipper_multiaddress_success>
306
+ </observers>
307
+ </checkout_multishipping_controller_success_action>
308
+ <!--save item detail -->
309
+ <sales_convert_quote_item_to_order_item>
310
+ <observers>
311
+ <shipperhq_splitrates_quoteitem_orderitem>
312
+ <type>singleton</type>
313
+ <class>shipperhq_shipper/observer</class>
314
+ <method>salesConvertQuoteItemToOrderItem</method>
315
+ </shipperhq_splitrates_quoteitem_orderitem>
316
+ </observers>
317
+ </sales_convert_quote_item_to_order_item>
318
+ </events>
319
+ <fieldsets>
320
+ <sales_convert_quote_address>
321
+ <dispatch_date>
322
+ <to_order>*</to_order>
323
+ </dispatch_date>
324
+ <delivery_date>
325
+ <to_order>*</to_order>
326
+ </delivery_date>
327
+ <carrier_type>
328
+ <to_order>*</to_order>
329
+ </carrier_type>
330
+ <carrier_id>
331
+ <to_order>*</to_order>
332
+ </carrier_id>
333
+ <carriergroup>
334
+ <to_order>*</to_order>
335
+ </carriergroup>
336
+ <carriergroup_shipping_details>
337
+ <to_order>*</to_order>
338
+ </carriergroup_shipping_details>
339
+ <carriergroup_shipping_html>
340
+ <to_order>*</to_order>
341
+ </carriergroup_shipping_html>
342
+ </sales_convert_quote_address>
343
+ <sales_convert_order>
344
+ <dispatch_date>
345
+ <to_quote_address_shipping>*</to_quote_address_shipping>
346
+ </dispatch_date>
347
+ <delivery_date>
348
+ <to_quote_address_shipping>*</to_quote_address_shipping>
349
+ </delivery_date>
350
+ <carrier_type>
351
+ <to_quote_address_shipping>*</to_quote_address_shipping>
352
+ </carrier_type>
353
+ <carrier_id>
354
+ <to_quote_address_shipping>*</to_quote_address_shipping>
355
+ </carrier_id>
356
+ <carriergroup>
357
+ <to_quote_address_shipping>*</to_quote_address_shipping>
358
+ </carriergroup>
359
+ <carriergroup_shipping_details>
360
+ <to_quote_address_shipping>*</to_quote_address_shipping>
361
+ </carriergroup_shipping_details>
362
+ <carriergroup_shipping_html>
363
+ <to_quote_address_shipping>*</to_quote_address_shipping>
364
+ </carriergroup_shipping_html>
365
+ </sales_convert_order>
366
+ <sales_convert_quote_item>
367
+ <carriergroup>
368
+ <to_order_item>*</to_order_item>
369
+ </carriergroup>
370
+ <carriergroup_id>
371
+ <to_order_item>*</to_order_item>
372
+ </carriergroup_id>
373
+ <carriergroup_shipping>
374
+ <to_order_item>*</to_order_item>
375
+ </carriergroup_shipping>
376
+ </sales_convert_quote_item>
377
+ <sales_convert_order_item>
378
+ <carriergroup>
379
+ <to_quote_item>*</to_quote_item>
380
+ </carriergroup>
381
+ <carriergroup_id>
382
+ <to_quote_item>*</to_quote_item>
383
+ </carriergroup_id>
384
+ <carriergroup_shipping>
385
+ <to_quote_item>*</to_quote_item>
386
+ </carriergroup_shipping>
387
+ </sales_convert_order_item>
388
+ </fieldsets>
389
+ <sales>
390
+ <shipping>
391
+ <carriers>
392
+ <shipper1>
393
+ <class>Shipperhq_Shipper_Model_Carrier_Shipper</class>
394
+ </shipper1>
395
+ <shipperadmin>
396
+ <class>Shipperhq_Shipper_Model_Carrier_Shipperadmin</class>
397
+ </shipperadmin>
398
+ </carriers>
399
+ </shipping>
400
+ <quote>
401
+ <item>
402
+ <product_attributes>
403
+ <shipperhq_shipping_group/>
404
+ <shipperhq_warehouse/>
405
+ <shipperhq_shipping_qty/>
406
+ <shipperhq_shipping_fee/>
407
+ <shipperhq_additional_price/>
408
+ <freight_class/>
409
+ <must_ship_freight/>
410
+ <shipperhq_nmfc_class/>
411
+ <shipperhq_nmfc_sub/>
412
+ <shipperhq_handling_fee/>
413
+ <shipperhq_carrier_code/>
414
+ <shipperhq_volume_weight/>
415
+ <shipperhq_declared_value/>
416
+ <ship_separately/>
417
+ <shipperhq_dim_group/>
418
+ <ship_box_tolerance/>
419
+ <ship_length/>
420
+ <ship_width/>
421
+ <ship_height/>
422
+ <length/>
423
+ <width/>
424
+ <height/>
425
+ <shipperhq_poss_boxes/>
426
+ <shipperhq_master_boxes/>
427
+ <package_id/>
428
+ <special_shipping_group/>
429
+ <volume_weight/>
430
+ <warehouse/>
431
+ <handling_id/>
432
+ <package_type/>
433
+ <packing_section_name/>
434
+ <shipperhq_malleable_product/>
435
+ </product_attributes>
436
+ </item>
437
+ </quote>
438
+ </sales>
439
+ </global>
440
+ <frontend>
441
+ <translate>
442
+ <modules>
443
+ <shipperhq_shipper>
444
+ <files>
445
+ <default>Shipperhq_Shipper.csv</default>
446
+ </files>
447
+ </shipperhq_shipper>
448
+ </modules>
449
+ </translate>
450
+ </frontend>
451
+ <adminhtml>
452
+ <layout>
453
+ <updates>
454
+ <shipperhq_shipper module="Shipperhq_Shipper">
455
+ <file>shipperhq/shipper.xml</file>
456
+ </shipperhq_shipper>
457
+ </updates>
458
+ </layout>
459
+ <translate>
460
+ <modules>
461
+ <Shipperhq_Shipper>
462
+ <files>
463
+ <default>Shipperhq_Shipper.csv</default>
464
+ </files>
465
+ </Shipperhq_Shipper>
466
+ </modules>
467
+ </translate>
468
+ <events>
469
+ <sales_order_place_after>
470
+ <observers>
471
+ <shipperhq_shipper_save_order_observer>
472
+ <class>shipperhq_shipper/observer_order</class>
473
+ <method>adminOrderSaveAfter</method>
474
+ </shipperhq_shipper_save_order_observer>
475
+ </observers>
476
+ </sales_order_place_after>
477
+ <sales_order_shipment_save_after>
478
+ <observers>
479
+ <shipperhq_shipper_save_shipment_observer>
480
+ <type>model</type>
481
+ <class>shipperhq_shipper/observer_shipment</class>
482
+ <method>processShipmentAddon</method>
483
+ </shipperhq_shipper_save_shipment_observer>
484
+ </observers>
485
+ </sales_order_shipment_save_after>
486
+ </events>
487
+ </adminhtml>
488
+ <default>
489
+ <carriers>
490
+ <shipper>
491
+ <active>0</active>
492
+ <title>Shipping Rates</title>
493
+ <api_key backend_model="adminhtml/system_config_backend_encrypted">
494
+ ZcmhDy912bavqmBnzMs6PCcUgQfv8ek82ty+zb9EBW4=
495
+ </api_key>
496
+ <password backend_model="adminhtml/system_config_backend_encrypted">
497
+ DTAzdo8+0u4DbuvI5NgP8V711uNH6COXD/e821CQSmY6gfOzH1enxEVmexG2sPbEQQGDbEelSQ4=
498
+ </password>
499
+ <url>http://sandbox.shipperhq.com/v1/</url>
500
+ <live_url>http://api.shipperhq.com/v1/</live_url>
501
+ <secure_url>https://api.shipperhq.com/v1/</secure_url>
502
+ <model>shipperhq_shipper/carrier_shipper</model>
503
+ <sandbox_mode>0</sandbox_mode>
504
+ <environment_scope>LIVE</environment_scope>
505
+ <hide_notify>0</hide_notify>
506
+ <display_transaction>0</display_transaction>
507
+ <sallowspecific>0</sallowspecific>
508
+ <showerrors>0</showerrors>
509
+ <showmethod>1</showmethod>
510
+ <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this
511
+ shipping method, please contact us.
512
+ </specificerrmsg>
513
+ <ws_timeout>120</ws_timeout>
514
+ <is_enterprise>0</is_enterprise>
515
+ </shipper>
516
+ <shipperadmin>
517
+ <active>1</active>
518
+ <title>Custom Shipping Rate</title>
519
+ <model>shipperhq_shipper/carrier_shipperadmin</model>
520
+ </shipperadmin>
521
+ </carriers>
522
+ </default>
523
+ </config>
app/code/community/Shipperhq/Shipper/etc/system.xml ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ *
5
+ * Webshopapps Shipping Module
6
+ *
7
+ * NOTICE OF LICENSE
8
+ *
9
+ * This source file is subject to the Open Software License (OSL 3.0)
10
+ * that is bundled with this package in the file LICENSE.txt.
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ * If you did not receive a copy of the license and are unable to
14
+ * obtain it through the world-wide-web, please send an email
15
+ * to license@magentocommerce.com so we can send you a copy immediately.
16
+ *
17
+ * DISCLAIMER
18
+ *
19
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
20
+ * versions in the future. If you wish to customize Magento for your
21
+ * needs please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * Shipper HQ Shipping
24
+ *
25
+ * @category ShipperHQ
26
+ * @package ShipperHQ_Shipping_Carrier
27
+ * @copyright Copyright (c) 2014 Zowta LLC (http://www.ShipperHQ.com)
28
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
+ * @author ShipperHQ Team sales@shipperhq.com
30
+ */
31
+ -->
32
+ <config>
33
+ <sections>
34
+ <carriers translate="label" module="shipping">
35
+ <groups>
36
+ <shipper translate="label">
37
+ <label>ShipperHQ</label>
38
+ <frontend_model>shipperhq_shipper/adminhtml_carrier_about</frontend_model>
39
+ <sort_order>2</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>1</show_in_website>
42
+ <show_in_store>1</show_in_store>
43
+ <comment>
44
+ <![CDATA[
45
+ This extension connects Magento to ShipperHQ, a powerful, easy-to-use eCommerce shipping management platform. <br />
46
+ For documentation and examples, please see the <a href="http://docs.shipperhq.com" target="_blank">ShipperHQ knowledge base</a>.<br /><br />
47
+ If you have questions about ShipperHQ or need support, visit <a href="http://www.ShipperHQ.com" target="_blank">http://www.ShipperHQ.com</a>.<br />
48
+ ShipperHQ is a product of <a href="http://www.webshopapps.com" target="_blank">WebShopApps</a>, developers of powerful shipping solutions for Magento. <br />
49
+ ]]>
50
+ </comment>
51
+ <fields>
52
+ <active translate="label">
53
+ <label>Enabled</label>
54
+ <frontend_type>select</frontend_type>
55
+ <source_model>adminhtml/system_config_source_yesno</source_model>
56
+ <sort_order>10</sort_order>
57
+ <show_in_default>1</show_in_default>
58
+ <show_in_website>1</show_in_website>
59
+ <show_in_store>1</show_in_store>
60
+ </active>
61
+ <title>
62
+ <label>Main Shipping Carrier Title</label>
63
+ <frontend_type>text</frontend_type>
64
+ <sort_order>20</sort_order>
65
+ <show_in_default>1</show_in_default>
66
+ <show_in_website>1</show_in_website>
67
+ <show_in_store>1</show_in_store>
68
+ <comment>Name of the main shipping carrier, also used for carrier title if no rates can be
69
+ found. This is updated dynamically from ShipperHQ
70
+ </comment>
71
+ </title>
72
+ <heading_shipperhq translate="label">
73
+ <label>ShipperHQ Configuration</label>
74
+ <frontend_model>shipperhq_shipper/adminhtml_carrier_heading</frontend_model>
75
+ <sort_order>100</sort_order>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>1</show_in_website>
78
+ </heading_shipperhq>
79
+ <environment_scope translate="label comment">
80
+ <label>Environment Scope</label>
81
+ <frontend_type>select</frontend_type>
82
+ <source_model>shipperhq_shipper/adminhtml_system_config_source_environmentscope
83
+ </source_model>
84
+ <sort_order>150</sort_order>
85
+ <show_in_default>1</show_in_default>
86
+ <show_in_website>1</show_in_website>
87
+ <show_in_store>0</show_in_store>
88
+ <comment>Select the relevant environment scope for ShipperHQ configuration settings
89
+ </comment>
90
+ </environment_scope>
91
+ <api_key>
92
+ <label>API Key</label>
93
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
94
+ <sort_order>170</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <show_in_store>1</show_in_store>
98
+ <comment>Obtain from under Websites in the ShipperHQ Dashboard</comment>
99
+ </api_key>
100
+ <password>
101
+ <label>Authentication Code</label>
102
+ <frontend_type>obscure</frontend_type>
103
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
104
+ <sort_order>180</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>1</show_in_website>
107
+ <show_in_store>1</show_in_store>
108
+ <comment>Obtain from under Websites in the ShipperHQ Dashboard</comment>
109
+ </password>
110
+ <refresh_methods translate="label">
111
+ <label>Refresh Shipping Methods</label>
112
+ <frontend_type>select</frontend_type>
113
+ <frontend_model>shipperhq_shipper/adminhtml_carrier_refreshcarriers</frontend_model>
114
+ <button_label>Refresh Now</button_label>
115
+ <sort_order>190</sort_order>
116
+ <show_in_default>1</show_in_default>
117
+ <show_in_website>0</show_in_website>
118
+ <show_in_store>0</show_in_store>
119
+ </refresh_methods>
120
+ <backup_carrier translate="label">
121
+ <label>Backup Shipping Carrier/Method</label>
122
+ <frontend_type>select</frontend_type>
123
+ <source_model>shipperhq_shipper/adminhtml_system_config_source_carriers</source_model>
124
+ <sort_order>195</sort_order>
125
+ <show_in_default>1</show_in_default>
126
+ <show_in_website>1</show_in_website>
127
+ <show_in_store>0</show_in_store>
128
+ <comment>In the unlikely event that ShipperHQ is unavailable, configure a backup carrier to
129
+ display.
130
+ This carrier should be configured but left disabled
131
+ </comment>
132
+ </backup_carrier>
133
+ <heading_advanced translate="label">
134
+ <label>Advanced Settings</label>
135
+ <frontend_model>shipperhq_shipper/adminhtml_carrier_heading</frontend_model>
136
+ <sort_order>300</sort_order>
137
+ <show_in_default>1</show_in_default>
138
+ <show_in_website>1</show_in_website>
139
+ </heading_advanced>
140
+ <!-- <item_attributes translate="label">
141
+ <label>Custom Item Attribute Codes</label>
142
+ <frontend_type>text</frontend_type>
143
+ <sort_order>320</sort_order>
144
+ <tooltip>
145
+ Pass extra item attributes to ShipperHQ.
146
+ This should be the attribute code, E.g if you wanted the freight ship price you would
147
+ use freight_ship_price.
148
+ You can specify multiple attributes by comma separating them.
149
+ </tooltip>
150
+ <show_in_default>1</show_in_default>
151
+ <show_in_website>1</show_in_website>
152
+ <show_in_store>1</show_in_store>
153
+ </item_attributes> -->
154
+ <custom_admin translate="label">
155
+ <label>Custom Shipping Rates in Admin</label>
156
+ <frontend_type>select</frontend_type>
157
+ <source_model>adminhtml/system_config_source_yesno</source_model>
158
+ <sort_order>340</sort_order>
159
+ <show_in_default>1</show_in_default>
160
+ <show_in_website>1</show_in_website>
161
+ <show_in_store>0</show_in_store>
162
+ <tooltip>Add fields to specify a custom shipping rate for orders placed in admin</tooltip>
163
+ </custom_admin>
164
+ <hide_notify translate="label comment">
165
+ <label>Hide Carrier Notifications at Checkout</label>
166
+ <frontend_type>select</frontend_type>
167
+ <source_model>adminhtml/system_config_source_yesno</source_model>
168
+ <sort_order>350</sort_order>
169
+ <show_in_default>1</show_in_default>
170
+ <show_in_website>1</show_in_website>
171
+ <show_in_store>0</show_in_store>
172
+ <tooltip>
173
+ Carriers may include notifications when their live rates have been modified. Set to yes if you wish to hide these notifications.
174
+ </tooltip>
175
+ </hide_notify>
176
+ <display_transaction translate="label comment">
177
+ <label>Display Transaction ID</label>
178
+ <frontend_type>select</frontend_type>
179
+ <source_model>adminhtml/system_config_source_yesno</source_model>
180
+ <sort_order>360</sort_order>
181
+ <show_in_default>1</show_in_default>
182
+ <show_in_website>1</show_in_website>
183
+ <show_in_store>0</show_in_store>
184
+ <comment>
185
+ Set to no unless advised by ShipperHQ team, used for debugging purposes
186
+ </comment>
187
+ </display_transaction>
188
+ <sandbox_mode translate="label comment">
189
+ <label>Sandbox Mode</label>
190
+ <frontend_type>select</frontend_type>
191
+ <source_model>adminhtml/system_config_source_yesno</source_model>
192
+ <sort_order>365</sort_order>
193
+ <show_in_default>1</show_in_default>
194
+ <show_in_website>1</show_in_website>
195
+ <show_in_store>0</show_in_store>
196
+ <comment>Set to Yes to use ShipperHQ Sandbox URL</comment>
197
+ </sandbox_mode>
198
+ <url>
199
+ <label>Sandbox URL</label>
200
+ <frontend_type>text</frontend_type>
201
+ <sort_order>370</sort_order>
202
+ <depends><sandbox_mode>1</sandbox_mode></depends>
203
+ <show_in_default>1</show_in_default>
204
+ <show_in_website>1</show_in_website>
205
+ <show_in_store>1</show_in_store>
206
+ </url>
207
+ <live_url translate="label">
208
+ <label>Live URL</label>
209
+ <frontend_type>text</frontend_type>
210
+ <sort_order>380</sort_order>
211
+ <depends><sandbox_mode>0</sandbox_mode></depends>
212
+ <show_in_default>1</show_in_default>
213
+ <show_in_website>1</show_in_website>
214
+ <show_in_store>0</show_in_store>
215
+ </live_url>
216
+ <secure_url translate="label">
217
+ <label>Secure URL</label>
218
+ <frontend_type>text</frontend_type>
219
+ <sort_order>390</sort_order>
220
+ <depends><sandbox_mode>0</sandbox_mode></depends>
221
+ <show_in_default>1</show_in_default>
222
+ <show_in_website>1</show_in_website>
223
+ <show_in_store>0</show_in_store>
224
+ </secure_url>
225
+ <heading_std_ship translate="label">
226
+ <label>Standard Shipping</label>
227
+ <frontend_model>shipperhq_shipper/adminhtml_carrier_heading</frontend_model>
228
+ <sort_order>400</sort_order>
229
+ <show_in_default>1</show_in_default>
230
+ <show_in_website>1</show_in_website>
231
+ </heading_std_ship>
232
+ <sallowspecific translate="label">
233
+ <label>Ship to Applicable Countries</label>
234
+ <frontend_type>select</frontend_type>
235
+ <sort_order>410</sort_order>
236
+ <frontend_class>shipping-applicable-country</frontend_class>
237
+ <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
238
+ <show_in_default>1</show_in_default>
239
+ <show_in_website>1</show_in_website>
240
+ <show_in_store>1</show_in_store>
241
+ </sallowspecific>
242
+ <specificcountry translate="label">
243
+ <label>Ship to Specific Countries</label>
244
+ <frontend_type>multiselect</frontend_type>
245
+ <sort_order>420</sort_order>
246
+ <source_model>adminhtml/system_config_source_country</source_model>
247
+ <show_in_default>1</show_in_default>
248
+ <show_in_website>1</show_in_website>
249
+ <show_in_store>1</show_in_store>
250
+ </specificcountry>
251
+ <showerrors translate="label">
252
+ <label>Show Method if Not Applicable</label>
253
+ <frontend_type>select</frontend_type>
254
+ <sort_order>430</sort_order>
255
+ <frontend_class>shipping-skip-hide</frontend_class>
256
+ <source_model>adminhtml/system_config_source_yesno</source_model>
257
+ <show_in_default>1</show_in_default>
258
+ <show_in_website>1</show_in_website>
259
+ <show_in_store>1</show_in_store>
260
+ </showerrors>
261
+ <specificerrmsg translate="label">
262
+ <label>Displayed Error Message</label>
263
+ <frontend_type>textarea</frontend_type>
264
+ <sort_order>440</sort_order>
265
+ <show_in_default>1</show_in_default>
266
+ <show_in_website>1</show_in_website>
267
+ <show_in_store>1</show_in_store>
268
+ <comment>
269
+ This error message will be displayed if no error message
270
+ is returned from ShipperHQ
271
+ </comment>
272
+ </specificerrmsg>
273
+ <sort_order translate="label">
274
+ <label>Sort Order</label>
275
+ <frontend_type>text</frontend_type>
276
+ <sort_order>450</sort_order>
277
+ <show_in_default>1</show_in_default>
278
+ <show_in_website>1</show_in_website>
279
+ <show_in_store>1</show_in_store>
280
+ </sort_order>
281
+ </fields>
282
+ </shipper>
283
+ </groups>
284
+ </carriers>
285
+ </sections>
286
+ </config>
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.10.php ADDED
@@ -0,0 +1,502 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $installer->run("
7
+ DROP TABLE IF EXISTS `{$installer->getTable('shipperhq_synchronize')}`;
8
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('shipperhq_synchronize')}` (
9
+ `synch_id` int(10) unsigned NOT NULL auto_increment COMMENT 'WebShopApps ShipperHQ',
10
+ `notification_id` int(10) unsigned NOT NULL default '0' COMMENT 'WebShopApps ShipperHQ',
11
+ `attribute_code` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
12
+ `attribute_type` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
13
+ `value` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
14
+ `status` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
15
+ `date_added` datetime NOT NULL COMMENT 'WebShopApps ShipperHQ',
16
+ PRIMARY KEY (`synch_id`)
17
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
18
+
19
+
20
+ select @entity_type_id:=entity_type_id from {$this->getTable('eav_entity_type')} where entity_type_code='catalog_product';
21
+
22
+ select @attribute_group_id:=attribute_group_id from {$this->getTable('eav_attribute_group')} where attribute_group_name='Shipping' and attribute_set_id = @attribute_set_id;
23
+
24
+
25
+ /* Free Shipping Flag */
26
+ insert ignore into {$this->getTable('eav_attribute')}
27
+ set entity_type_id = @entity_type_id,
28
+ attribute_code = 'shipperhq_free_shipping',
29
+ backend_type = 'int',
30
+ frontend_input = 'boolean',
31
+ is_required = 0,
32
+ is_user_defined = 1,
33
+ frontend_label = 'Free Shipping';
34
+
35
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_free_shipping';
36
+
37
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
38
+ set attribute_id = @attribute_id,
39
+ is_visible = 1,
40
+ used_in_product_listing = 0,
41
+ is_filterable_in_search = 0;
42
+
43
+
44
+ /* Shipping Group attribute for modules like i.e ProductMatrix */
45
+ insert ignore into {$this->getTable('eav_attribute')}
46
+ set entity_type_id = @entity_type_id,
47
+ attribute_code = 'shipperhq_shipping_group',
48
+ backend_type = 'varchar',
49
+ frontend_input = 'multiselect',
50
+ backend_model = 'eav/entity_attribute_backend_array',
51
+ is_required = 0,
52
+ is_user_defined = 1,
53
+ frontend_label = 'Shipping Group';
54
+
55
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_group';
56
+
57
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
58
+ set attribute_id = @attribute_id,
59
+ is_visible = 1,
60
+ used_in_product_listing = 0,
61
+ is_filterable_in_search = 0;
62
+
63
+ /* Warehouse attribute for modules like i.e Dropship */
64
+ insert ignore into {$this->getTable('eav_attribute')}
65
+ set entity_type_id = @entity_type_id,
66
+ attribute_code = 'shipperhq_warehouse',
67
+ backend_type = 'text',
68
+ frontend_input = 'multiselect',
69
+ backend_model = 'eav/entity_attribute_backend_array',
70
+ is_required = 0,
71
+ is_user_defined = 1,
72
+ frontend_label = 'Origin';
73
+
74
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_warehouse';
75
+
76
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
77
+ set attribute_id = @attribute_id,
78
+ is_visible = 1,
79
+ used_in_product_listing = 0,
80
+ is_filterable_in_search = 0;
81
+
82
+ /* Shipping Qty */
83
+ insert ignore into {$this->getTable('eav_attribute')}
84
+ set entity_type_id = @entity_type_id,
85
+ attribute_code = 'shipperhq_shipping_qty',
86
+ backend_type = 'int',
87
+ frontend_input = 'text',
88
+ is_required = 0,
89
+ is_user_defined = 1,
90
+ frontend_label = 'Shipping Qty';
91
+
92
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_qty';
93
+
94
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
95
+ set attribute_id = @attribute_id,
96
+ is_visible = 1,
97
+ used_in_product_listing = 0,
98
+ is_filterable_in_search = 0;
99
+
100
+ /* Shipping Price */
101
+ insert ignore into {$this->getTable('eav_attribute')}
102
+ set entity_type_id = @entity_type_id,
103
+ attribute_code = 'shipperhq_shipping_fee',
104
+ backend_type = 'decimal',
105
+ frontend_input = 'price',
106
+ is_required = 0,
107
+ is_user_defined = 1,
108
+ frontend_label = 'Shipping Fee';
109
+
110
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_fee';
111
+
112
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
113
+ set attribute_id = @attribute_id,
114
+ is_visible = 1,
115
+ used_in_product_listing = 0,
116
+ is_filterable_in_search = 0;
117
+
118
+ /* Additional Price */
119
+ insert ignore into {$this->getTable('eav_attribute')}
120
+ set entity_type_id = @entity_type_id,
121
+ attribute_code = 'shipperhq_additional_price',
122
+ backend_type = 'decimal',
123
+ frontend_input = 'price',
124
+ is_required = 0,
125
+ is_user_defined = 1,
126
+ frontend_label = 'Additional Price';
127
+
128
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_additional_price';
129
+
130
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
131
+ set attribute_id = @attribute_id,
132
+ is_visible = 1,
133
+ used_in_product_listing = 0,
134
+ is_filterable_in_search = 0;
135
+
136
+
137
+ /* freight class */
138
+ insert ignore into {$this->getTable('eav_attribute')}
139
+ set entity_type_id = @entity_type_id,
140
+ attribute_code = 'shipperhq_freight_class',
141
+ backend_type = 'int',
142
+ frontend_input = 'text',
143
+ is_required = 0,
144
+ is_user_defined = 1,
145
+ frontend_label = 'Freight Class';
146
+
147
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_freight_class';
148
+
149
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
150
+ set attribute_id = @attribute_id,
151
+ is_visible = 1,
152
+ used_in_product_listing = 0,
153
+ is_filterable_in_search = 0;
154
+
155
+ /* nmfc */
156
+ insert ignore into {$this->getTable('eav_attribute')}
157
+ set entity_type_id = @entity_type_id,
158
+ attribute_code = 'shipperhq_nmfc_class',
159
+ backend_type = 'text',
160
+ frontend_input = 'text',
161
+ is_required = 0,
162
+ is_user_defined = 1,
163
+ frontend_label = 'NMFC Class';
164
+
165
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_nmfc_class';
166
+
167
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
168
+ set attribute_id = @attribute_id,
169
+ is_visible = 1,
170
+ used_in_product_listing = 0,
171
+ is_filterable_in_search = 0;
172
+
173
+ /* Handling Price */
174
+ insert ignore into {$this->getTable('eav_attribute')}
175
+ set entity_type_id = @entity_type_id,
176
+ attribute_code = 'shipperhq_handling_fee',
177
+ backend_type = 'decimal',
178
+ frontend_input = 'price',
179
+ is_required = 0,
180
+ is_user_defined = 1,
181
+ frontend_label = 'Handling Fee';
182
+
183
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_handling_fee';
184
+
185
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
186
+ set attribute_id = @attribute_id,
187
+ is_visible = 1,
188
+ used_in_product_listing = 0,
189
+ is_filterable_in_search = 0;
190
+
191
+
192
+ /* Carrier Code */
193
+ insert ignore into {$this->getTable('eav_attribute')}
194
+ set entity_type_id = @entity_type_id,
195
+ attribute_code = 'shipperhq_carrier_code',
196
+ backend_type = 'text',
197
+ frontend_input = 'text',
198
+ is_required = 0,
199
+ is_user_defined = 1,
200
+ frontend_label = 'Carrier Code';
201
+
202
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_carrier_code';
203
+
204
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
205
+ set attribute_id = @attribute_id,
206
+ is_visible = 1,
207
+ used_in_product_listing = 0,
208
+ is_filterable_in_search = 0;
209
+
210
+
211
+ /* Volume Weight */
212
+ insert ignore into {$this->getTable('eav_attribute')}
213
+ set entity_type_id = @entity_type_id,
214
+ attribute_code = 'shipperhq_volume_weight',
215
+ backend_type = 'decimal',
216
+ frontend_input = 'text',
217
+ is_required = 0,
218
+ is_user_defined = 1,
219
+ frontend_label = 'Volume Weight';
220
+
221
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_volume_weight';
222
+
223
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
224
+ set attribute_id = @attribute_id,
225
+ is_visible = 1,
226
+ used_in_product_listing = 0,
227
+ is_filterable_in_search = 0;
228
+
229
+ /* Declared Value */
230
+ insert ignore into {$this->getTable('eav_attribute')}
231
+ set entity_type_id = @entity_type_id,
232
+ attribute_code = 'shipperhq_declared_value',
233
+ backend_type = 'decimal',
234
+ frontend_input = 'price',
235
+ is_required = 0,
236
+ is_user_defined = 1,
237
+ frontend_label = 'Declared Value',
238
+ note = 'The deemed cost of this product for customs & insurance purposes';
239
+
240
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_declared_value';
241
+
242
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
243
+ set attribute_id = @attribute_id,
244
+ is_visible = 1,
245
+ used_in_product_listing = 0,
246
+ is_filterable_in_search = 0;
247
+
248
+ /*Ship Separately*/
249
+ insert ignore into {$this->getTable('eav_attribute')}
250
+ set entity_type_id = @entity_type_id,
251
+ attribute_code = 'ship_separately',
252
+ backend_type = 'int',
253
+ frontend_input = 'boolean',
254
+ is_user_defined = 1,
255
+ is_required = 0,
256
+ frontend_label = 'Ship Separately';
257
+
258
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_separately';
259
+
260
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
261
+ set attribute_id = @attribute_id,
262
+ is_visible = 1,
263
+ used_in_product_listing = 0,
264
+ is_filterable_in_search = 0;
265
+
266
+ /*Dimensional Group*/
267
+ insert ignore into {$this->getTable('eav_attribute')}
268
+ set entity_type_id = @entity_type_id,
269
+ attribute_code = 'shipperhq_dim_group',
270
+ backend_type = 'varchar',
271
+ frontend_input = 'select',
272
+ backend_model = 'eav/entity_attribute_backend_array',
273
+ is_user_defined = 1,
274
+ is_required = 0,
275
+ frontend_label = 'ShipperHQ Dimensional Rule Group';
276
+
277
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_dim_group';
278
+
279
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
280
+ set attribute_id = @attribute_id,
281
+ is_visible = 1,
282
+ used_in_product_listing = 0,
283
+ is_filterable_in_search = 0;
284
+
285
+ /*Dimensional Ship Length*/
286
+ insert ignore into {$this->getTable('eav_attribute')}
287
+ set entity_type_id = @entity_type_id,
288
+ attribute_code = 'ship_length',
289
+ backend_type = 'decimal',
290
+ frontend_input = 'text',
291
+ is_required = 0,
292
+ is_user_defined = 1,
293
+ frontend_label = 'Dimension Length';
294
+
295
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_length';
296
+
297
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
298
+ set attribute_id = @attribute_id,
299
+ is_visible = 1,
300
+ used_in_product_listing = 0,
301
+ is_filterable_in_search = 0;
302
+
303
+
304
+ /*Dimensional Ship Width*/
305
+ insert ignore into {$this->getTable('eav_attribute')}
306
+ set entity_type_id = @entity_type_id,
307
+ attribute_code = 'ship_width',
308
+ backend_type = 'decimal',
309
+ frontend_input = 'text',
310
+ is_required = 0,
311
+ is_user_defined = 1,
312
+ frontend_label = 'Dimension Width';
313
+
314
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_width';
315
+
316
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
317
+ set attribute_id = @attribute_id,
318
+ is_visible = 1,
319
+ used_in_product_listing = 0,
320
+ is_filterable_in_search = 0;
321
+
322
+ /*Dimensional Ship Height*/
323
+ insert ignore into {$this->getTable('eav_attribute')}
324
+ set entity_type_id = @entity_type_id,
325
+ attribute_code = 'ship_height',
326
+ backend_type = 'decimal',
327
+ frontend_input = 'text',
328
+ is_required = 0,
329
+ is_user_defined = 1,
330
+ frontend_label = 'Dimension Height';
331
+
332
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_height';
333
+
334
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
335
+ set attribute_id = @attribute_id,
336
+ is_visible = 1,
337
+ used_in_product_listing = 0,
338
+ is_filterable_in_search = 0;
339
+
340
+ /*Dimensional Possible Ship Boxes*/
341
+ insert ignore into {$this->getTable('eav_attribute')}
342
+ set entity_type_id = @entity_type_id,
343
+ attribute_code = 'shipperhq_poss_boxes',
344
+ backend_type = 'varchar',
345
+ backend_model = 'eav/entity_attribute_backend_array',
346
+ frontend_input = 'multiselect',
347
+ is_required = 0,
348
+ is_user_defined = 1,
349
+ frontend_label = 'Possible Packing Boxes';
350
+
351
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_poss_boxes';
352
+
353
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
354
+ set attribute_id = @attribute_id,
355
+ is_visible = 1,
356
+ used_in_product_listing = 0,
357
+ is_filterable_in_search = 0;
358
+ ");
359
+
360
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
361
+
362
+ $attributeSetArr = $installer->getConnection()->fetchAll("SELECT attribute_set_id FROM {$this->getTable('eav_attribute_set')} WHERE entity_type_id={$entityTypeId}");
363
+
364
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
365
+ $dimAttributeCodes = array('ship_separately' => '2',
366
+ 'shipperhq_dim_group' => '1',
367
+ 'shipperhq_volume_weight' => '9',
368
+ 'ship_length' => '10',
369
+ 'ship_width' => '11',
370
+ 'ship_height' => '12',
371
+ 'shipperhq_poss_boxes' => '20',
372
+ 'shipperhq_declared_value' => '21'
373
+ );
374
+
375
+ foreach ($attributeSetArr as $attr) {
376
+ $attributeSetId = $attr['attribute_set_id'];
377
+
378
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
379
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
380
+
381
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
382
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
383
+
384
+ foreach($stdAttributeCodes as $code => $sort) {
385
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
386
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
387
+ }
388
+
389
+ foreach($dimAttributeCodes as $code => $sort) {
390
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
391
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
392
+ }
393
+ };
394
+
395
+
396
+
397
+ if (Mage::helper('wsalogger')->getNewVersion() > 10) {
398
+
399
+
400
+ $isCheckout = array(
401
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
402
+ 'comment' => 'Shipperhq Shipper',
403
+ 'nullable' => 'false',
404
+ 'default' => '0'
405
+ );
406
+
407
+ $carrierType = array(
408
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
409
+ 'comment' => 'Shipperhq Carrier Type',
410
+ 'nullable' => 'true',
411
+ );
412
+
413
+ $dispatchDate = array(
414
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
415
+ 'length' => 20,
416
+ 'comment' => 'Dispatch Date',
417
+ 'nullable' => 'true');
418
+
419
+ $deliveryDate = array(
420
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
421
+ 'length' => 20,
422
+ 'comment' => 'Expected Delivery',
423
+ 'nullable' => 'true');
424
+
425
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
426
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
427
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
428
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
429
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
430
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
431
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
432
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
433
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
434
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
435
+
436
+
437
+ } else {
438
+
439
+ $quoteAddressTable = $installer->getTable('sales/quote_address');
440
+ $quoteRateTable = $installer->getTable('sales/quote_address_shipping_rate');
441
+ $orderTable = $installer->getTable('sales/order');
442
+
443
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'is_checkout')){
444
+ $installer->run("
445
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD is_checkout smallint(1) unsigned NOT NULL default '0' COMMENT 'Shipperhq Shipper';
446
+ ");
447
+ }
448
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'carrier_type')){
449
+ $installer->run("
450
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
451
+ ");
452
+ }
453
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'dispatch_date')){
454
+ $installer->run("
455
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
456
+ ");
457
+ }
458
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'delivery_date')){
459
+ $installer->run("
460
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD delivery_date text COMMENT 'Shipperhq Expected Delivery Date';
461
+ ");
462
+ }
463
+
464
+
465
+
466
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'carrier_type')){
467
+ $installer->run("
468
+ ALTER IGNORE TABLE {$quoteRateTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
469
+ ");
470
+ }
471
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'dispatch_date')){
472
+ $installer->run("
473
+ ALTER IGNORE TABLE {$quoteRateTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
474
+ ");
475
+ }
476
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'delivery_date')){
477
+ $installer->run("
478
+ ALTER IGNORE TABLE {$quoteRateTable} ADD delivery_date text COMMENT 'Shipperhq Delivery Date';
479
+ ");
480
+ }
481
+
482
+
483
+
484
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'carrier_type')){
485
+ $installer->run("
486
+ ALTER IGNORE TABLE {$orderTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
487
+ ");
488
+ }
489
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'dispatch_date')){
490
+ $installer->run("
491
+ ALTER IGNORE TABLE {$orderTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
492
+ ");
493
+ }
494
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'delivery_date')){
495
+ $installer->run("
496
+ ALTER IGNORE TABLE {$orderTable} ADD delivery_date text COMMENT 'Shipperhq Delivery Date';
497
+ ");
498
+ }
499
+
500
+ }
501
+
502
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.11.php ADDED
@@ -0,0 +1,526 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $installer->run("
7
+ DROP TABLE IF EXISTS `{$installer->getTable('shipperhq_synchronize')}`;
8
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('shipperhq_synchronize')}` (
9
+ `synch_id` int(10) unsigned NOT NULL auto_increment COMMENT 'WebShopApps ShipperHQ',
10
+ `notification_id` int(10) unsigned NOT NULL default '0' COMMENT 'WebShopApps ShipperHQ',
11
+ `attribute_code` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
12
+ `attribute_type` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
13
+ `value` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
14
+ `status` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
15
+ `date_added` datetime NOT NULL COMMENT 'WebShopApps ShipperHQ',
16
+ PRIMARY KEY (`synch_id`)
17
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
18
+
19
+
20
+ select @entity_type_id:=entity_type_id from {$this->getTable('eav_entity_type')} where entity_type_code='catalog_product';
21
+
22
+ select @attribute_group_id:=attribute_group_id from {$this->getTable('eav_attribute_group')} where attribute_group_name='Shipping' and attribute_set_id = @attribute_set_id;
23
+
24
+
25
+ /* Free Shipping Flag */
26
+ insert ignore into {$this->getTable('eav_attribute')}
27
+ set entity_type_id = @entity_type_id,
28
+ attribute_code = 'shipperhq_free_shipping',
29
+ backend_type = 'int',
30
+ frontend_input = 'boolean',
31
+ is_required = 0,
32
+ is_user_defined = 1,
33
+ frontend_label = 'Free Shipping';
34
+
35
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_free_shipping';
36
+
37
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
38
+ set attribute_id = @attribute_id,
39
+ is_visible = 1,
40
+ used_in_product_listing = 0,
41
+ is_filterable_in_search = 0;
42
+
43
+
44
+ /* Shipping Group attribute for modules like i.e ProductMatrix */
45
+ insert ignore into {$this->getTable('eav_attribute')}
46
+ set entity_type_id = @entity_type_id,
47
+ attribute_code = 'shipperhq_shipping_group',
48
+ backend_type = 'varchar',
49
+ frontend_input = 'multiselect',
50
+ backend_model = 'eav/entity_attribute_backend_array',
51
+ is_required = 0,
52
+ is_user_defined = 1,
53
+ frontend_label = 'Shipping Group';
54
+
55
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_group';
56
+
57
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
58
+ set attribute_id = @attribute_id,
59
+ is_visible = 1,
60
+ used_in_product_listing = 0,
61
+ is_filterable_in_search = 0,
62
+ is_global = 0;
63
+
64
+
65
+ /* Warehouse attribute for modules like i.e Dropship */
66
+ insert ignore into {$this->getTable('eav_attribute')}
67
+ set entity_type_id = @entity_type_id,
68
+ attribute_code = 'shipperhq_warehouse',
69
+ backend_type = 'text',
70
+ frontend_input = 'multiselect',
71
+ backend_model = 'eav/entity_attribute_backend_array',
72
+ is_required = 0,
73
+ is_user_defined = 1,
74
+ frontend_label = 'Origin';
75
+
76
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_warehouse';
77
+
78
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
79
+ set attribute_id = @attribute_id,
80
+ is_visible = 1,
81
+ used_in_product_listing = 0,
82
+ is_filterable_in_search = 0,
83
+ is_global = 0;
84
+
85
+ /* Shipping Qty */
86
+ insert ignore into {$this->getTable('eav_attribute')}
87
+ set entity_type_id = @entity_type_id,
88
+ attribute_code = 'shipperhq_shipping_qty',
89
+ backend_type = 'int',
90
+ frontend_input = 'text',
91
+ is_required = 0,
92
+ is_user_defined = 1,
93
+ frontend_label = 'Shipping Qty';
94
+
95
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_qty';
96
+
97
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
98
+ set attribute_id = @attribute_id,
99
+ is_visible = 1,
100
+ used_in_product_listing = 0,
101
+ is_filterable_in_search = 0;
102
+
103
+ /* Shipping Price */
104
+ insert ignore into {$this->getTable('eav_attribute')}
105
+ set entity_type_id = @entity_type_id,
106
+ attribute_code = 'shipperhq_shipping_fee',
107
+ backend_type = 'decimal',
108
+ frontend_input = 'price',
109
+ is_required = 0,
110
+ is_user_defined = 1,
111
+ frontend_label = 'Shipping Fee';
112
+
113
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_fee';
114
+
115
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
116
+ set attribute_id = @attribute_id,
117
+ is_visible = 1,
118
+ used_in_product_listing = 0,
119
+ is_filterable_in_search = 0,
120
+ is_global = 0;
121
+
122
+ /* Additional Price */
123
+ insert ignore into {$this->getTable('eav_attribute')}
124
+ set entity_type_id = @entity_type_id,
125
+ attribute_code = 'shipperhq_additional_price',
126
+ backend_type = 'decimal',
127
+ frontend_input = 'price',
128
+ is_required = 0,
129
+ is_user_defined = 1,
130
+ frontend_label = 'Additional Price';
131
+
132
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_additional_price';
133
+
134
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
135
+ set attribute_id = @attribute_id,
136
+ is_visible = 1,
137
+ used_in_product_listing = 0,
138
+ is_filterable_in_search = 0;
139
+
140
+
141
+ /* freight class */
142
+ insert ignore into {$this->getTable('eav_attribute')}
143
+ set entity_type_id = @entity_type_id,
144
+ attribute_code = 'shipperhq_freight_class',
145
+ backend_type = 'int',
146
+ frontend_input = 'text',
147
+ is_required = 0,
148
+ is_user_defined = 1,
149
+ frontend_label = 'Freight Class';
150
+
151
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_freight_class';
152
+
153
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
154
+ set attribute_id = @attribute_id,
155
+ is_visible = 1,
156
+ used_in_product_listing = 0,
157
+ is_filterable_in_search = 0;
158
+
159
+ /* nmfc */
160
+ insert ignore into {$this->getTable('eav_attribute')}
161
+ set entity_type_id = @entity_type_id,
162
+ attribute_code = 'shipperhq_nmfc_class',
163
+ backend_type = 'text',
164
+ frontend_input = 'text',
165
+ is_required = 0,
166
+ is_user_defined = 1,
167
+ frontend_label = 'NMFC Class';
168
+
169
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_nmfc_class';
170
+
171
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
172
+ set attribute_id = @attribute_id,
173
+ is_visible = 1,
174
+ used_in_product_listing = 0,
175
+ is_filterable_in_search = 0;
176
+
177
+ /* Handling Price */
178
+ insert ignore into {$this->getTable('eav_attribute')}
179
+ set entity_type_id = @entity_type_id,
180
+ attribute_code = 'shipperhq_handling_fee',
181
+ backend_type = 'decimal',
182
+ frontend_input = 'price',
183
+ is_required = 0,
184
+ is_user_defined = 1,
185
+ frontend_label = 'Handling Fee';
186
+
187
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_handling_fee';
188
+
189
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
190
+ set attribute_id = @attribute_id,
191
+ is_visible = 1,
192
+ used_in_product_listing = 0,
193
+ is_filterable_in_search = 0;
194
+
195
+
196
+ /* Carrier Code */
197
+ insert ignore into {$this->getTable('eav_attribute')}
198
+ set entity_type_id = @entity_type_id,
199
+ attribute_code = 'shipperhq_carrier_code',
200
+ backend_type = 'text',
201
+ frontend_input = 'text',
202
+ is_required = 0,
203
+ is_user_defined = 1,
204
+ frontend_label = 'Carrier Code';
205
+
206
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_carrier_code';
207
+
208
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
209
+ set attribute_id = @attribute_id,
210
+ is_visible = 1,
211
+ used_in_product_listing = 0,
212
+ is_filterable_in_search = 0;
213
+
214
+
215
+ /* Volume Weight */
216
+ insert ignore into {$this->getTable('eav_attribute')}
217
+ set entity_type_id = @entity_type_id,
218
+ attribute_code = 'shipperhq_volume_weight',
219
+ backend_type = 'decimal',
220
+ frontend_input = 'text',
221
+ is_required = 0,
222
+ is_user_defined = 1,
223
+ frontend_label = 'Volume Weight';
224
+
225
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_volume_weight';
226
+
227
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
228
+ set attribute_id = @attribute_id,
229
+ is_visible = 1,
230
+ used_in_product_listing = 0,
231
+ is_filterable_in_search = 0;
232
+
233
+ /* Declared Value */
234
+ insert ignore into {$this->getTable('eav_attribute')}
235
+ set entity_type_id = @entity_type_id,
236
+ attribute_code = 'shipperhq_declared_value',
237
+ backend_type = 'decimal',
238
+ frontend_input = 'price',
239
+ is_required = 0,
240
+ is_user_defined = 1,
241
+ frontend_label = 'Declared Value',
242
+ note = 'The deemed cost of this product for customs & insurance purposes';
243
+
244
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_declared_value';
245
+
246
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
247
+ set attribute_id = @attribute_id,
248
+ is_visible = 1,
249
+ used_in_product_listing = 0,
250
+ is_filterable_in_search = 0;
251
+
252
+ /*Ship Separately*/
253
+ insert ignore into {$this->getTable('eav_attribute')}
254
+ set entity_type_id = @entity_type_id,
255
+ attribute_code = 'ship_separately',
256
+ backend_type = 'int',
257
+ frontend_input = 'boolean',
258
+ is_user_defined = 1,
259
+ is_required = 0,
260
+ frontend_label = 'Ship Separately';
261
+
262
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_separately';
263
+
264
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
265
+ set attribute_id = @attribute_id,
266
+ is_visible = 1,
267
+ used_in_product_listing = 0,
268
+ is_filterable_in_search = 0;
269
+
270
+ /*Dimensional Group*/
271
+ insert ignore into {$this->getTable('eav_attribute')}
272
+ set entity_type_id = @entity_type_id,
273
+ attribute_code = 'shipperhq_dim_group',
274
+ backend_type = 'varchar',
275
+ frontend_input = 'select',
276
+ backend_model = 'eav/entity_attribute_backend_array',
277
+ is_user_defined = 1,
278
+ is_required = 0,
279
+ frontend_label = 'ShipperHQ Dimensional Rule Group';
280
+
281
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_dim_group';
282
+
283
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
284
+ set attribute_id = @attribute_id,
285
+ is_visible = 1,
286
+ used_in_product_listing = 0,
287
+ is_filterable_in_search = 0;
288
+
289
+ /*Dimensional Ship Length*/
290
+ insert ignore into {$this->getTable('eav_attribute')}
291
+ set entity_type_id = @entity_type_id,
292
+ attribute_code = 'ship_length',
293
+ backend_type = 'decimal',
294
+ frontend_input = 'text',
295
+ is_required = 0,
296
+ is_user_defined = 1,
297
+ frontend_label = 'Dimension Length';
298
+
299
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_length';
300
+
301
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
302
+ set attribute_id = @attribute_id,
303
+ is_visible = 1,
304
+ used_in_product_listing = 0,
305
+ is_filterable_in_search = 0;
306
+
307
+
308
+ /*Dimensional Ship Width*/
309
+ insert ignore into {$this->getTable('eav_attribute')}
310
+ set entity_type_id = @entity_type_id,
311
+ attribute_code = 'ship_width',
312
+ backend_type = 'decimal',
313
+ frontend_input = 'text',
314
+ is_required = 0,
315
+ is_user_defined = 1,
316
+ frontend_label = 'Dimension Width';
317
+
318
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_width';
319
+
320
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
321
+ set attribute_id = @attribute_id,
322
+ is_visible = 1,
323
+ used_in_product_listing = 0,
324
+ is_filterable_in_search = 0;
325
+
326
+ /*Dimensional Ship Height*/
327
+ insert ignore into {$this->getTable('eav_attribute')}
328
+ set entity_type_id = @entity_type_id,
329
+ attribute_code = 'ship_height',
330
+ backend_type = 'decimal',
331
+ frontend_input = 'text',
332
+ is_required = 0,
333
+ is_user_defined = 1,
334
+ frontend_label = 'Dimension Height';
335
+
336
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_height';
337
+
338
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
339
+ set attribute_id = @attribute_id,
340
+ is_visible = 1,
341
+ used_in_product_listing = 0,
342
+ is_filterable_in_search = 0;
343
+
344
+ /*Dimensional Possible Ship Boxes*/
345
+ insert ignore into {$this->getTable('eav_attribute')}
346
+ set entity_type_id = @entity_type_id,
347
+ attribute_code = 'shipperhq_poss_boxes',
348
+ backend_type = 'varchar',
349
+ backend_model = 'eav/entity_attribute_backend_array',
350
+ frontend_input = 'multiselect',
351
+ is_required = 0,
352
+ is_user_defined = 1,
353
+ frontend_label = 'Possible Packing Boxes';
354
+
355
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_poss_boxes';
356
+
357
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
358
+ set attribute_id = @attribute_id,
359
+ is_visible = 1,
360
+ used_in_product_listing = 0,
361
+ is_filterable_in_search = 0;
362
+
363
+ /*Dimensional Ship Box Tolerance */
364
+ insert ignore into {$this->getTable('eav_attribute')}
365
+ set entity_type_id = @entity_type_id,
366
+ attribute_code = 'ship_box_tolerance',
367
+ backend_type = 'int',
368
+ frontend_input = 'text',
369
+ is_user_defined = 1,
370
+ is_required = 0,
371
+ note = 'Note: Ignore if unsure',
372
+ frontend_label = 'Box Tolerance';
373
+
374
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_box_tolerance';
375
+
376
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
377
+ set attribute_id = @attribute_id,
378
+ is_visible = 1,
379
+ used_in_product_listing = 0,
380
+ is_filterable_in_search = 0;
381
+ ");
382
+
383
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
384
+
385
+ $attributeSetArr = $installer->getConnection()->fetchAll("SELECT attribute_set_id FROM {$this->getTable('eav_attribute_set')} WHERE entity_type_id={$entityTypeId}");
386
+
387
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
388
+ $dimAttributeCodes = array('ship_separately' => '2',
389
+ 'shipperhq_dim_group' => '1',
390
+ 'shipperhq_volume_weight' => '9',
391
+ 'ship_length' => '10',
392
+ 'ship_width' => '11',
393
+ 'ship_height' => '12',
394
+ 'shipperhq_poss_boxes' => '20',
395
+ 'ship_box_tolerance' => '22',
396
+ 'shipperhq_declared_value' => '25'
397
+ );
398
+
399
+ foreach ($attributeSetArr as $attr) {
400
+ $attributeSetId = $attr['attribute_set_id'];
401
+
402
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
403
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
404
+
405
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
406
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
407
+
408
+ foreach($stdAttributeCodes as $code => $sort) {
409
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
410
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
411
+ }
412
+
413
+ foreach($dimAttributeCodes as $code => $sort) {
414
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
415
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
416
+ }
417
+ };
418
+
419
+
420
+
421
+ if (Mage::helper('wsalogger')->getNewVersion() > 10) {
422
+
423
+
424
+ $isCheckout = array(
425
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
426
+ 'comment' => 'Shipperhq Shipper',
427
+ 'nullable' => 'false',
428
+ 'default' => '0'
429
+ );
430
+
431
+ $carrierType = array(
432
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
433
+ 'comment' => 'Shipperhq Carrier Type',
434
+ 'nullable' => 'true',
435
+ );
436
+
437
+ $dispatchDate = array(
438
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
439
+ 'length' => 20,
440
+ 'comment' => 'Dispatch Date',
441
+ 'nullable' => 'true');
442
+
443
+ $deliveryDate = array(
444
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
445
+ 'length' => 20,
446
+ 'comment' => 'Expected Delivery',
447
+ 'nullable' => 'true');
448
+
449
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
450
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
451
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
452
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
453
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
454
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
455
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
456
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
457
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
458
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
459
+
460
+
461
+ } else {
462
+
463
+ $quoteAddressTable = $installer->getTable('sales/quote_address');
464
+ $quoteRateTable = $installer->getTable('sales/quote_address_shipping_rate');
465
+ $orderTable = $installer->getTable('sales/order');
466
+
467
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'is_checkout')){
468
+ $installer->run("
469
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD is_checkout smallint(1) unsigned NOT NULL default '0' COMMENT 'Shipperhq Shipper';
470
+ ");
471
+ }
472
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'carrier_type')){
473
+ $installer->run("
474
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
475
+ ");
476
+ }
477
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'dispatch_date')){
478
+ $installer->run("
479
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
480
+ ");
481
+ }
482
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'delivery_date')){
483
+ $installer->run("
484
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD delivery_date text COMMENT 'Shipperhq Expected Delivery Date';
485
+ ");
486
+ }
487
+
488
+
489
+
490
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'carrier_type')){
491
+ $installer->run("
492
+ ALTER IGNORE TABLE {$quoteRateTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
493
+ ");
494
+ }
495
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'dispatch_date')){
496
+ $installer->run("
497
+ ALTER IGNORE TABLE {$quoteRateTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
498
+ ");
499
+ }
500
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'delivery_date')){
501
+ $installer->run("
502
+ ALTER IGNORE TABLE {$quoteRateTable} ADD delivery_date text COMMENT 'Shipperhq Delivery Date';
503
+ ");
504
+ }
505
+
506
+
507
+
508
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'carrier_type')){
509
+ $installer->run("
510
+ ALTER IGNORE TABLE {$orderTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
511
+ ");
512
+ }
513
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'dispatch_date')){
514
+ $installer->run("
515
+ ALTER IGNORE TABLE {$orderTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
516
+ ");
517
+ }
518
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'delivery_date')){
519
+ $installer->run("
520
+ ALTER IGNORE TABLE {$orderTable} ADD delivery_date text COMMENT 'Shipperhq Delivery Date';
521
+ ");
522
+ }
523
+
524
+ }
525
+
526
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.12.php ADDED
@@ -0,0 +1,556 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $installer->run("
7
+ DROP TABLE IF EXISTS `{$installer->getTable('shipperhq_synchronize')}`;
8
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('shipperhq_synchronize')}` (
9
+ `synch_id` int(10) unsigned NOT NULL auto_increment COMMENT 'WebShopApps ShipperHQ',
10
+ `notification_id` int(10) unsigned NOT NULL default '0' COMMENT 'WebShopApps ShipperHQ',
11
+ `attribute_code` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
12
+ `attribute_type` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
13
+ `value` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
14
+ `status` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
15
+ `date_added` datetime NOT NULL COMMENT 'WebShopApps ShipperHQ',
16
+ PRIMARY KEY (`synch_id`)
17
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
18
+
19
+
20
+ select @entity_type_id:=entity_type_id from {$this->getTable('eav_entity_type')} where entity_type_code='catalog_product';
21
+
22
+ select @attribute_group_id:=attribute_group_id from {$this->getTable('eav_attribute_group')} where attribute_group_name='Shipping' and attribute_set_id = @attribute_set_id;
23
+
24
+
25
+ /* Free Shipping Flag */
26
+ insert ignore into {$this->getTable('eav_attribute')}
27
+ set entity_type_id = @entity_type_id,
28
+ attribute_code = 'shipperhq_free_shipping',
29
+ backend_type = 'int',
30
+ frontend_input = 'boolean',
31
+ is_required = 0,
32
+ is_user_defined = 1,
33
+ frontend_label = 'Free Shipping';
34
+
35
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_free_shipping';
36
+
37
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
38
+ set attribute_id = @attribute_id,
39
+ is_visible = 1,
40
+ used_in_product_listing = 0,
41
+ is_filterable_in_search = 0;
42
+
43
+
44
+ /* Shipping Group attribute for modules like i.e ProductMatrix */
45
+ insert ignore into {$this->getTable('eav_attribute')}
46
+ set entity_type_id = @entity_type_id,
47
+ attribute_code = 'shipperhq_shipping_group',
48
+ backend_type = 'varchar',
49
+ frontend_input = 'multiselect',
50
+ backend_model = 'eav/entity_attribute_backend_array',
51
+ is_required = 0,
52
+ is_user_defined = 1,
53
+ frontend_label = 'Shipping Group';
54
+
55
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_group';
56
+
57
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
58
+ set attribute_id = @attribute_id,
59
+ is_visible = 1,
60
+ used_in_product_listing = 0,
61
+ is_filterable_in_search = 0,
62
+ is_global = 0;
63
+
64
+
65
+ /* Warehouse attribute for modules like i.e Dropship */
66
+ insert ignore into {$this->getTable('eav_attribute')}
67
+ set entity_type_id = @entity_type_id,
68
+ attribute_code = 'shipperhq_warehouse',
69
+ backend_type = 'text',
70
+ frontend_input = 'multiselect',
71
+ backend_model = 'eav/entity_attribute_backend_array',
72
+ is_required = 0,
73
+ is_user_defined = 1,
74
+ frontend_label = 'Origin';
75
+
76
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_warehouse';
77
+
78
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
79
+ set attribute_id = @attribute_id,
80
+ is_visible = 1,
81
+ used_in_product_listing = 0,
82
+ is_filterable_in_search = 0,
83
+ is_global = 0;
84
+
85
+ /* Shipping Qty */
86
+ insert ignore into {$this->getTable('eav_attribute')}
87
+ set entity_type_id = @entity_type_id,
88
+ attribute_code = 'shipperhq_shipping_qty',
89
+ backend_type = 'int',
90
+ frontend_input = 'text',
91
+ is_required = 0,
92
+ is_user_defined = 1,
93
+ frontend_label = 'Shipping Qty';
94
+
95
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_qty';
96
+
97
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
98
+ set attribute_id = @attribute_id,
99
+ is_visible = 1,
100
+ used_in_product_listing = 0,
101
+ is_filterable_in_search = 0;
102
+
103
+ /* Shipping Price */
104
+ insert ignore into {$this->getTable('eav_attribute')}
105
+ set entity_type_id = @entity_type_id,
106
+ attribute_code = 'shipperhq_shipping_fee',
107
+ backend_type = 'decimal',
108
+ frontend_input = 'price',
109
+ is_required = 0,
110
+ is_user_defined = 1,
111
+ frontend_label = 'Shipping Fee';
112
+
113
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_fee';
114
+
115
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
116
+ set attribute_id = @attribute_id,
117
+ is_visible = 1,
118
+ used_in_product_listing = 0,
119
+ is_filterable_in_search = 0,
120
+ is_global = 0;
121
+
122
+ /* Additional Price */
123
+ insert ignore into {$this->getTable('eav_attribute')}
124
+ set entity_type_id = @entity_type_id,
125
+ attribute_code = 'shipperhq_additional_price',
126
+ backend_type = 'decimal',
127
+ frontend_input = 'price',
128
+ is_required = 0,
129
+ is_user_defined = 1,
130
+ frontend_label = 'Additional Price';
131
+
132
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_additional_price';
133
+
134
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
135
+ set attribute_id = @attribute_id,
136
+ is_visible = 1,
137
+ used_in_product_listing = 0,
138
+ is_filterable_in_search = 0;
139
+
140
+
141
+ /* freight class */
142
+ insert ignore into {$this->getTable('eav_attribute')}
143
+ set entity_type_id = @entity_type_id,
144
+ attribute_code = 'freight_class',
145
+ backend_type = 'int',
146
+ frontend_input = 'text',
147
+ is_required = 0,
148
+ is_user_defined = 1,
149
+ frontend_label = 'Freight Class';
150
+
151
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='freight_class';
152
+
153
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
154
+ set attribute_id = @attribute_id,
155
+ is_visible = 1,
156
+ used_in_product_listing = 0,
157
+ is_filterable_in_search = 0;
158
+
159
+ /* nmfc */
160
+ insert ignore into {$this->getTable('eav_attribute')}
161
+ set entity_type_id = @entity_type_id,
162
+ attribute_code = 'shipperhq_nmfc_class',
163
+ backend_type = 'text',
164
+ frontend_input = 'text',
165
+ is_required = 0,
166
+ is_user_defined = 1,
167
+ frontend_label = 'NMFC Class';
168
+
169
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_nmfc_class';
170
+
171
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
172
+ set attribute_id = @attribute_id,
173
+ is_visible = 1,
174
+ used_in_product_listing = 0,
175
+ is_filterable_in_search = 0;
176
+
177
+ /*Must Ship Freight*/
178
+ insert ignore into {$this->getTable('eav_attribute')}
179
+ set entity_type_id = @entity_type_id,
180
+ attribute_code = 'must_ship_freight',
181
+ backend_type = 'int',
182
+ frontend_input = 'boolean',
183
+ is_required = 0,
184
+ is_user_defined = 1,
185
+ frontend_label = 'Must ship freight';
186
+
187
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='must_ship_freight';
188
+
189
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
190
+ set attribute_id = @attribute_id,
191
+ is_visible = 1,
192
+ used_in_product_listing = 0,
193
+ is_filterable_in_search = 0;
194
+
195
+ /* Handling Price */
196
+ insert ignore into {$this->getTable('eav_attribute')}
197
+ set entity_type_id = @entity_type_id,
198
+ attribute_code = 'shipperhq_handling_fee',
199
+ backend_type = 'decimal',
200
+ frontend_input = 'price',
201
+ is_required = 0,
202
+ is_user_defined = 1,
203
+ frontend_label = 'Handling Fee';
204
+
205
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_handling_fee';
206
+
207
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
208
+ set attribute_id = @attribute_id,
209
+ is_visible = 1,
210
+ used_in_product_listing = 0,
211
+ is_filterable_in_search = 0;
212
+
213
+
214
+ /* Carrier Code */
215
+ insert ignore into {$this->getTable('eav_attribute')}
216
+ set entity_type_id = @entity_type_id,
217
+ attribute_code = 'shipperhq_carrier_code',
218
+ backend_type = 'text',
219
+ frontend_input = 'text',
220
+ is_required = 0,
221
+ is_user_defined = 1,
222
+ frontend_label = 'Carrier Code';
223
+
224
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_carrier_code';
225
+
226
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
227
+ set attribute_id = @attribute_id,
228
+ is_visible = 1,
229
+ used_in_product_listing = 0,
230
+ is_filterable_in_search = 0;
231
+
232
+
233
+ /* Volume Weight */
234
+ insert ignore into {$this->getTable('eav_attribute')}
235
+ set entity_type_id = @entity_type_id,
236
+ attribute_code = 'shipperhq_volume_weight',
237
+ backend_type = 'decimal',
238
+ frontend_input = 'text',
239
+ is_required = 0,
240
+ is_user_defined = 1,
241
+ frontend_label = 'Volume Weight';
242
+
243
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_volume_weight';
244
+
245
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
246
+ set attribute_id = @attribute_id,
247
+ is_visible = 1,
248
+ used_in_product_listing = 0,
249
+ is_filterable_in_search = 0;
250
+
251
+ /* Declared Value */
252
+ insert ignore into {$this->getTable('eav_attribute')}
253
+ set entity_type_id = @entity_type_id,
254
+ attribute_code = 'shipperhq_declared_value',
255
+ backend_type = 'decimal',
256
+ frontend_input = 'price',
257
+ is_required = 0,
258
+ is_user_defined = 1,
259
+ frontend_label = 'Declared Value',
260
+ note = 'The deemed cost of this product for customs & insurance purposes';
261
+
262
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_declared_value';
263
+
264
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
265
+ set attribute_id = @attribute_id,
266
+ is_visible = 1,
267
+ used_in_product_listing = 0,
268
+ is_filterable_in_search = 0;
269
+
270
+ /*Ship Separately*/
271
+ insert ignore into {$this->getTable('eav_attribute')}
272
+ set entity_type_id = @entity_type_id,
273
+ attribute_code = 'ship_separately',
274
+ backend_type = 'int',
275
+ frontend_input = 'boolean',
276
+ is_user_defined = 1,
277
+ is_required = 0,
278
+ frontend_label = 'Ship Separately';
279
+
280
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_separately';
281
+
282
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
283
+ set attribute_id = @attribute_id,
284
+ is_visible = 1,
285
+ used_in_product_listing = 0,
286
+ is_filterable_in_search = 0;
287
+
288
+ /*Dimensional Group*/
289
+ insert ignore into {$this->getTable('eav_attribute')}
290
+ set entity_type_id = @entity_type_id,
291
+ attribute_code = 'shipperhq_dim_group',
292
+ backend_type = 'varchar',
293
+ frontend_input = 'select',
294
+ backend_model = 'eav/entity_attribute_backend_array',
295
+ is_user_defined = 1,
296
+ is_required = 0,
297
+ frontend_label = 'ShipperHQ Dimensional Rule Group';
298
+
299
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_dim_group';
300
+
301
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
302
+ set attribute_id = @attribute_id,
303
+ is_visible = 1,
304
+ used_in_product_listing = 0,
305
+ is_filterable_in_search = 0;
306
+
307
+ /*Dimensional Ship Length*/
308
+ insert ignore into {$this->getTable('eav_attribute')}
309
+ set entity_type_id = @entity_type_id,
310
+ attribute_code = 'ship_length',
311
+ backend_type = 'decimal',
312
+ frontend_input = 'text',
313
+ is_required = 0,
314
+ is_user_defined = 1,
315
+ frontend_label = 'Dimension Length';
316
+
317
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_length';
318
+
319
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
320
+ set attribute_id = @attribute_id,
321
+ is_visible = 1,
322
+ used_in_product_listing = 0,
323
+ is_filterable_in_search = 0;
324
+
325
+
326
+ /*Dimensional Ship Width*/
327
+ insert ignore into {$this->getTable('eav_attribute')}
328
+ set entity_type_id = @entity_type_id,
329
+ attribute_code = 'ship_width',
330
+ backend_type = 'decimal',
331
+ frontend_input = 'text',
332
+ is_required = 0,
333
+ is_user_defined = 1,
334
+ frontend_label = 'Dimension Width';
335
+
336
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_width';
337
+
338
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
339
+ set attribute_id = @attribute_id,
340
+ is_visible = 1,
341
+ used_in_product_listing = 0,
342
+ is_filterable_in_search = 0;
343
+
344
+ /*Dimensional Ship Height*/
345
+ insert ignore into {$this->getTable('eav_attribute')}
346
+ set entity_type_id = @entity_type_id,
347
+ attribute_code = 'ship_height',
348
+ backend_type = 'decimal',
349
+ frontend_input = 'text',
350
+ is_required = 0,
351
+ is_user_defined = 1,
352
+ frontend_label = 'Dimension Height';
353
+
354
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_height';
355
+
356
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
357
+ set attribute_id = @attribute_id,
358
+ is_visible = 1,
359
+ used_in_product_listing = 0,
360
+ is_filterable_in_search = 0;
361
+
362
+ /*Dimensional Possible Ship Boxes*/
363
+ insert ignore into {$this->getTable('eav_attribute')}
364
+ set entity_type_id = @entity_type_id,
365
+ attribute_code = 'shipperhq_poss_boxes',
366
+ backend_type = 'varchar',
367
+ backend_model = 'eav/entity_attribute_backend_array',
368
+ frontend_input = 'multiselect',
369
+ is_required = 0,
370
+ is_user_defined = 1,
371
+ frontend_label = 'Possible Packing Boxes';
372
+
373
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_poss_boxes';
374
+
375
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
376
+ set attribute_id = @attribute_id,
377
+ is_visible = 1,
378
+ used_in_product_listing = 0,
379
+ is_filterable_in_search = 0;
380
+
381
+ /*Dimensional Ship Box Tolerance */
382
+ insert ignore into {$this->getTable('eav_attribute')}
383
+ set entity_type_id = @entity_type_id,
384
+ attribute_code = 'ship_box_tolerance',
385
+ backend_type = 'int',
386
+ frontend_input = 'text',
387
+ is_user_defined = 1,
388
+ is_required = 0,
389
+ note = 'Note: Ignore if unsure',
390
+ frontend_label = 'Box Tolerance';
391
+
392
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_box_tolerance';
393
+
394
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
395
+ set attribute_id = @attribute_id,
396
+ is_visible = 1,
397
+ used_in_product_listing = 0,
398
+ is_filterable_in_search = 0;
399
+ ");
400
+
401
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
402
+
403
+ $attributeSetArr = $installer->getConnection()->fetchAll("SELECT attribute_set_id FROM {$this->getTable('eav_attribute_set')} WHERE entity_type_id={$entityTypeId}");
404
+
405
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
406
+ $dimAttributeCodes = array('ship_separately' => '2',
407
+ 'shipperhq_dim_group' => '1',
408
+ 'shipperhq_volume_weight' => '9',
409
+ 'ship_length' => '10',
410
+ 'ship_width' => '11',
411
+ 'ship_height' => '12',
412
+ 'shipperhq_poss_boxes' => '20',
413
+ 'ship_box_tolerance' => '22',
414
+ 'shipperhq_declared_value' => '25'
415
+ );
416
+ $freightAttributeCodes = array(
417
+ 'freight_class' => '1',
418
+ 'must_ship_freight' =>'10'
419
+ );
420
+
421
+ foreach ($attributeSetArr as $attr) {
422
+ $attributeSetId = $attr['attribute_set_id'];
423
+
424
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
425
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
426
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Freight Shipping', '101');
427
+
428
+
429
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
430
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
431
+ $freightAttGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Freight Shipping');
432
+
433
+ foreach($stdAttributeCodes as $code => $sort) {
434
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
435
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
436
+ }
437
+
438
+ foreach($dimAttributeCodes as $code => $sort) {
439
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
440
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
441
+ }
442
+
443
+ foreach($freightAttributeCodes as $code => $sort) {
444
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
445
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $freightAttGroupId, $attributeId, $sort);
446
+ }
447
+ };
448
+
449
+
450
+
451
+ if (Mage::helper('wsalogger')->getNewVersion() > 10) {
452
+
453
+
454
+ $isCheckout = array(
455
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
456
+ 'comment' => 'Shipperhq Shipper',
457
+ 'nullable' => 'false',
458
+ 'default' => '0'
459
+ );
460
+
461
+ $carrierType = array(
462
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
463
+ 'comment' => 'Shipperhq Carrier Type',
464
+ 'nullable' => 'true',
465
+ );
466
+
467
+ $dispatchDate = array(
468
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
469
+ 'length' => 20,
470
+ 'comment' => 'Dispatch Date',
471
+ 'nullable' => 'true');
472
+
473
+ $deliveryDate = array(
474
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
475
+ 'length' => 20,
476
+ 'comment' => 'Expected Delivery',
477
+ 'nullable' => 'true');
478
+
479
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
480
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
481
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
482
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
483
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
484
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
485
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
486
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
487
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
488
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
489
+
490
+
491
+ } else {
492
+
493
+ $quoteAddressTable = $installer->getTable('sales/quote_address');
494
+ $quoteRateTable = $installer->getTable('sales/quote_address_shipping_rate');
495
+ $orderTable = $installer->getTable('sales/order');
496
+
497
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'is_checkout')){
498
+ $installer->run("
499
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD is_checkout smallint(1) unsigned NOT NULL default '0' COMMENT 'Shipperhq Shipper';
500
+ ");
501
+ }
502
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'carrier_type')){
503
+ $installer->run("
504
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
505
+ ");
506
+ }
507
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'dispatch_date')){
508
+ $installer->run("
509
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
510
+ ");
511
+ }
512
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'delivery_date')){
513
+ $installer->run("
514
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD delivery_date text COMMENT 'Shipperhq Expected Delivery Date';
515
+ ");
516
+ }
517
+
518
+
519
+
520
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'carrier_type')){
521
+ $installer->run("
522
+ ALTER IGNORE TABLE {$quoteRateTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
523
+ ");
524
+ }
525
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'dispatch_date')){
526
+ $installer->run("
527
+ ALTER IGNORE TABLE {$quoteRateTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
528
+ ");
529
+ }
530
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'delivery_date')){
531
+ $installer->run("
532
+ ALTER IGNORE TABLE {$quoteRateTable} ADD delivery_date text COMMENT 'Shipperhq Delivery Date';
533
+ ");
534
+ }
535
+
536
+
537
+
538
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'carrier_type')){
539
+ $installer->run("
540
+ ALTER IGNORE TABLE {$orderTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
541
+ ");
542
+ }
543
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'dispatch_date')){
544
+ $installer->run("
545
+ ALTER IGNORE TABLE {$orderTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
546
+ ");
547
+ }
548
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'delivery_date')){
549
+ $installer->run("
550
+ ALTER IGNORE TABLE {$orderTable} ADD delivery_date text COMMENT 'Shipperhq Delivery Date';
551
+ ");
552
+ }
553
+
554
+ }
555
+
556
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.13.php ADDED
@@ -0,0 +1,568 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $installer->run("
7
+ DROP TABLE IF EXISTS `{$installer->getTable('shipperhq_synchronize')}`;
8
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('shipperhq_synchronize')}` (
9
+ `synch_id` int(10) unsigned NOT NULL auto_increment COMMENT 'WebShopApps ShipperHQ',
10
+ `notification_id` int(10) unsigned NOT NULL default '0' COMMENT 'WebShopApps ShipperHQ',
11
+ `attribute_code` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
12
+ `attribute_type` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
13
+ `value` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
14
+ `status` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
15
+ `date_added` datetime NOT NULL COMMENT 'WebShopApps ShipperHQ',
16
+ PRIMARY KEY (`synch_id`)
17
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
18
+
19
+
20
+ select @entity_type_id:=entity_type_id from {$this->getTable('eav_entity_type')} where entity_type_code='catalog_product';
21
+
22
+ select @attribute_group_id:=attribute_group_id from {$this->getTable('eav_attribute_group')} where attribute_group_name='Shipping' and attribute_set_id = @attribute_set_id;
23
+
24
+
25
+ /* Free Shipping Flag */
26
+ insert ignore into {$this->getTable('eav_attribute')}
27
+ set entity_type_id = @entity_type_id,
28
+ attribute_code = 'shipperhq_free_shipping',
29
+ backend_type = 'int',
30
+ frontend_input = 'boolean',
31
+ is_required = 0,
32
+ is_user_defined = 1,
33
+ frontend_label = 'Free Shipping';
34
+
35
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_free_shipping';
36
+
37
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
38
+ set attribute_id = @attribute_id,
39
+ is_visible = 1,
40
+ used_in_product_listing = 0,
41
+ is_filterable_in_search = 0;
42
+
43
+
44
+ /* Shipping Group attribute for modules like i.e ProductMatrix */
45
+ insert ignore into {$this->getTable('eav_attribute')}
46
+ set entity_type_id = @entity_type_id,
47
+ attribute_code = 'shipperhq_shipping_group',
48
+ backend_type = 'varchar',
49
+ frontend_input = 'multiselect',
50
+ backend_model = 'eav/entity_attribute_backend_array',
51
+ is_required = 0,
52
+ is_user_defined = 1,
53
+ frontend_label = 'Shipping Group';
54
+
55
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_group';
56
+
57
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
58
+ set attribute_id = @attribute_id,
59
+ is_visible = 1,
60
+ used_in_product_listing = 0,
61
+ is_filterable_in_search = 0,
62
+ is_global = 0;
63
+
64
+
65
+ /* Warehouse attribute for modules like i.e Dropship */
66
+ insert ignore into {$this->getTable('eav_attribute')}
67
+ set entity_type_id = @entity_type_id,
68
+ attribute_code = 'shipperhq_warehouse',
69
+ backend_type = 'text',
70
+ frontend_input = 'multiselect',
71
+ backend_model = 'eav/entity_attribute_backend_array',
72
+ is_required = 0,
73
+ is_user_defined = 1,
74
+ frontend_label = 'Origin';
75
+
76
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_warehouse';
77
+
78
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
79
+ set attribute_id = @attribute_id,
80
+ is_visible = 1,
81
+ used_in_product_listing = 0,
82
+ is_filterable_in_search = 0,
83
+ is_global = 0;
84
+
85
+ /* Shipping Qty */
86
+ insert ignore into {$this->getTable('eav_attribute')}
87
+ set entity_type_id = @entity_type_id,
88
+ attribute_code = 'shipperhq_shipping_qty',
89
+ backend_type = 'int',
90
+ frontend_input = 'text',
91
+ is_required = 0,
92
+ is_user_defined = 1,
93
+ frontend_label = 'Shipping Qty';
94
+
95
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_qty';
96
+
97
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
98
+ set attribute_id = @attribute_id,
99
+ is_visible = 1,
100
+ used_in_product_listing = 0,
101
+ is_filterable_in_search = 0;
102
+
103
+ /* Shipping Price */
104
+ insert ignore into {$this->getTable('eav_attribute')}
105
+ set entity_type_id = @entity_type_id,
106
+ attribute_code = 'shipperhq_shipping_fee',
107
+ backend_type = 'decimal',
108
+ frontend_input = 'price',
109
+ is_required = 0,
110
+ is_user_defined = 1,
111
+ frontend_label = 'Shipping Fee';
112
+
113
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_fee';
114
+
115
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
116
+ set attribute_id = @attribute_id,
117
+ is_visible = 1,
118
+ used_in_product_listing = 0,
119
+ is_filterable_in_search = 0,
120
+ is_global = 0;
121
+
122
+ /* Additional Price */
123
+ insert ignore into {$this->getTable('eav_attribute')}
124
+ set entity_type_id = @entity_type_id,
125
+ attribute_code = 'shipperhq_additional_price',
126
+ backend_type = 'decimal',
127
+ frontend_input = 'price',
128
+ is_required = 0,
129
+ is_user_defined = 1,
130
+ frontend_label = 'Additional Price';
131
+
132
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_additional_price';
133
+
134
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
135
+ set attribute_id = @attribute_id,
136
+ is_visible = 1,
137
+ used_in_product_listing = 0,
138
+ is_filterable_in_search = 0;
139
+
140
+
141
+ /* freight class */
142
+ insert ignore into {$this->getTable('eav_attribute')}
143
+ set entity_type_id = @entity_type_id,
144
+ attribute_code = 'freight_class',
145
+ backend_type = 'int',
146
+ frontend_input = 'text',
147
+ is_required = 0,
148
+ is_user_defined = 1,
149
+ frontend_label = 'Freight Class';
150
+
151
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='freight_class';
152
+
153
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
154
+ set attribute_id = @attribute_id,
155
+ is_visible = 1,
156
+ used_in_product_listing = 0,
157
+ is_filterable_in_search = 0;
158
+
159
+ /* nmfc */
160
+ insert ignore into {$this->getTable('eav_attribute')}
161
+ set entity_type_id = @entity_type_id,
162
+ attribute_code = 'shipperhq_nmfc_class',
163
+ backend_type = 'text',
164
+ frontend_input = 'text',
165
+ is_required = 0,
166
+ is_user_defined = 1,
167
+ frontend_label = 'NMFC Class';
168
+
169
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_nmfc_class';
170
+
171
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
172
+ set attribute_id = @attribute_id,
173
+ is_visible = 1,
174
+ used_in_product_listing = 0,
175
+ is_filterable_in_search = 0;
176
+
177
+ /*Must Ship Freight*/
178
+ insert ignore into {$this->getTable('eav_attribute')}
179
+ set entity_type_id = @entity_type_id,
180
+ attribute_code = 'must_ship_freight',
181
+ backend_type = 'int',
182
+ frontend_input = 'boolean',
183
+ is_required = 0,
184
+ is_user_defined = 1,
185
+ frontend_label = 'Must ship freight';
186
+
187
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='must_ship_freight';
188
+
189
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
190
+ set attribute_id = @attribute_id,
191
+ is_visible = 1,
192
+ used_in_product_listing = 0,
193
+ is_filterable_in_search = 0;
194
+
195
+ /* Handling Price */
196
+ insert ignore into {$this->getTable('eav_attribute')}
197
+ set entity_type_id = @entity_type_id,
198
+ attribute_code = 'shipperhq_handling_fee',
199
+ backend_type = 'decimal',
200
+ frontend_input = 'price',
201
+ is_required = 0,
202
+ is_user_defined = 1,
203
+ frontend_label = 'Handling Fee';
204
+
205
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_handling_fee';
206
+
207
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
208
+ set attribute_id = @attribute_id,
209
+ is_visible = 1,
210
+ used_in_product_listing = 0,
211
+ is_filterable_in_search = 0;
212
+
213
+
214
+ /* Carrier Code */
215
+ insert ignore into {$this->getTable('eav_attribute')}
216
+ set entity_type_id = @entity_type_id,
217
+ attribute_code = 'shipperhq_carrier_code',
218
+ backend_type = 'text',
219
+ frontend_input = 'text',
220
+ is_required = 0,
221
+ is_user_defined = 1,
222
+ frontend_label = 'Carrier Code';
223
+
224
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_carrier_code';
225
+
226
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
227
+ set attribute_id = @attribute_id,
228
+ is_visible = 1,
229
+ used_in_product_listing = 0,
230
+ is_filterable_in_search = 0;
231
+
232
+
233
+ /* Volume Weight */
234
+ insert ignore into {$this->getTable('eav_attribute')}
235
+ set entity_type_id = @entity_type_id,
236
+ attribute_code = 'shipperhq_volume_weight',
237
+ backend_type = 'decimal',
238
+ frontend_input = 'text',
239
+ is_required = 0,
240
+ is_user_defined = 1,
241
+ frontend_label = 'Volume Weight';
242
+
243
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_volume_weight';
244
+
245
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
246
+ set attribute_id = @attribute_id,
247
+ is_visible = 1,
248
+ used_in_product_listing = 0,
249
+ is_filterable_in_search = 0;
250
+
251
+ /* Declared Value */
252
+ insert ignore into {$this->getTable('eav_attribute')}
253
+ set entity_type_id = @entity_type_id,
254
+ attribute_code = 'shipperhq_declared_value',
255
+ backend_type = 'decimal',
256
+ frontend_input = 'price',
257
+ is_required = 0,
258
+ is_user_defined = 1,
259
+ frontend_label = 'Declared Value',
260
+ note = 'The deemed cost of this product for customs & insurance purposes';
261
+
262
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_declared_value';
263
+
264
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
265
+ set attribute_id = @attribute_id,
266
+ is_visible = 1,
267
+ used_in_product_listing = 0,
268
+ is_filterable_in_search = 0;
269
+
270
+ /*Ship Separately*/
271
+ insert ignore into {$this->getTable('eav_attribute')}
272
+ set entity_type_id = @entity_type_id,
273
+ attribute_code = 'ship_separately',
274
+ backend_type = 'int',
275
+ frontend_input = 'boolean',
276
+ is_user_defined = 1,
277
+ is_required = 0,
278
+ frontend_label = 'Ship Separately';
279
+
280
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_separately';
281
+
282
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
283
+ set attribute_id = @attribute_id,
284
+ is_visible = 1,
285
+ used_in_product_listing = 0,
286
+ is_filterable_in_search = 0;
287
+
288
+ /*Dimensional Group*/
289
+ insert ignore into {$this->getTable('eav_attribute')}
290
+ set entity_type_id = @entity_type_id,
291
+ attribute_code = 'shipperhq_dim_group',
292
+ backend_type = 'varchar',
293
+ frontend_input = 'select',
294
+ backend_model = 'eav/entity_attribute_backend_array',
295
+ is_user_defined = 1,
296
+ is_required = 0,
297
+ frontend_label = 'ShipperHQ Dimensional Rule Group';
298
+
299
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_dim_group';
300
+
301
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
302
+ set attribute_id = @attribute_id,
303
+ is_visible = 1,
304
+ used_in_product_listing = 0,
305
+ is_filterable_in_search = 0;
306
+
307
+ /*Dimensional Ship Length*/
308
+ insert ignore into {$this->getTable('eav_attribute')}
309
+ set entity_type_id = @entity_type_id,
310
+ attribute_code = 'ship_length',
311
+ backend_type = 'decimal',
312
+ frontend_input = 'text',
313
+ is_required = 0,
314
+ is_user_defined = 1,
315
+ frontend_label = 'Dimension Length';
316
+
317
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_length';
318
+
319
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
320
+ set attribute_id = @attribute_id,
321
+ is_visible = 1,
322
+ used_in_product_listing = 0,
323
+ is_filterable_in_search = 0;
324
+
325
+
326
+ /*Dimensional Ship Width*/
327
+ insert ignore into {$this->getTable('eav_attribute')}
328
+ set entity_type_id = @entity_type_id,
329
+ attribute_code = 'ship_width',
330
+ backend_type = 'decimal',
331
+ frontend_input = 'text',
332
+ is_required = 0,
333
+ is_user_defined = 1,
334
+ frontend_label = 'Dimension Width';
335
+
336
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_width';
337
+
338
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
339
+ set attribute_id = @attribute_id,
340
+ is_visible = 1,
341
+ used_in_product_listing = 0,
342
+ is_filterable_in_search = 0;
343
+
344
+ /*Dimensional Ship Height*/
345
+ insert ignore into {$this->getTable('eav_attribute')}
346
+ set entity_type_id = @entity_type_id,
347
+ attribute_code = 'ship_height',
348
+ backend_type = 'decimal',
349
+ frontend_input = 'text',
350
+ is_required = 0,
351
+ is_user_defined = 1,
352
+ frontend_label = 'Dimension Height';
353
+
354
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_height';
355
+
356
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
357
+ set attribute_id = @attribute_id,
358
+ is_visible = 1,
359
+ used_in_product_listing = 0,
360
+ is_filterable_in_search = 0;
361
+
362
+ /*Dimensional Possible Ship Boxes*/
363
+ insert ignore into {$this->getTable('eav_attribute')}
364
+ set entity_type_id = @entity_type_id,
365
+ attribute_code = 'shipperhq_poss_boxes',
366
+ backend_type = 'varchar',
367
+ backend_model = 'eav/entity_attribute_backend_array',
368
+ frontend_input = 'multiselect',
369
+ is_required = 0,
370
+ is_user_defined = 1,
371
+ frontend_label = 'Possible Packing Boxes';
372
+
373
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_poss_boxes';
374
+
375
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
376
+ set attribute_id = @attribute_id,
377
+ is_visible = 1,
378
+ used_in_product_listing = 0,
379
+ is_filterable_in_search = 0;
380
+
381
+ /*Dimensional Ship Box Tolerance */
382
+ insert ignore into {$this->getTable('eav_attribute')}
383
+ set entity_type_id = @entity_type_id,
384
+ attribute_code = 'ship_box_tolerance',
385
+ backend_type = 'int',
386
+ frontend_input = 'text',
387
+ is_user_defined = 1,
388
+ is_required = 0,
389
+ note = 'Note: Ignore if unsure',
390
+ frontend_label = 'Box Tolerance';
391
+
392
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_box_tolerance';
393
+
394
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
395
+ set attribute_id = @attribute_id,
396
+ is_visible = 1,
397
+ used_in_product_listing = 0,
398
+ is_filterable_in_search = 0;
399
+ ");
400
+
401
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
402
+
403
+ $attributeSetArr = $installer->getConnection()->fetchAll("SELECT attribute_set_id FROM {$this->getTable('eav_attribute_set')} WHERE entity_type_id={$entityTypeId}");
404
+
405
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
406
+ $dimAttributeCodes = array('ship_separately' => '2',
407
+ 'shipperhq_dim_group' => '1',
408
+ 'shipperhq_volume_weight' => '9',
409
+ 'ship_length' => '10',
410
+ 'ship_width' => '11',
411
+ 'ship_height' => '12',
412
+ 'shipperhq_poss_boxes' => '20',
413
+ 'ship_box_tolerance' => '22',
414
+ 'shipperhq_declared_value' => '25'
415
+ );
416
+ $freightAttributeCodes = array(
417
+ 'freight_class' => '1',
418
+ 'must_ship_freight' =>'10'
419
+ );
420
+
421
+ foreach ($attributeSetArr as $attr) {
422
+ $attributeSetId = $attr['attribute_set_id'];
423
+
424
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
425
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
426
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Freight Shipping', '101');
427
+
428
+
429
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
430
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
431
+ $freightAttGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Freight Shipping');
432
+
433
+ foreach($stdAttributeCodes as $code => $sort) {
434
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
435
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
436
+ }
437
+
438
+ foreach($dimAttributeCodes as $code => $sort) {
439
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
440
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
441
+ }
442
+
443
+ foreach($freightAttributeCodes as $code => $sort) {
444
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
445
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $freightAttGroupId, $attributeId, $sort);
446
+ }
447
+ };
448
+
449
+
450
+
451
+ if (Mage::helper('wsalogger')->getNewVersion() > 10) {
452
+
453
+
454
+ $isCheckout = array(
455
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
456
+ 'comment' => 'Shipperhq Shipper',
457
+ 'nullable' => 'false',
458
+ 'default' => '0'
459
+ );
460
+
461
+ $carrierType = array(
462
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
463
+ 'comment' => 'Shipperhq Carrier Type',
464
+ 'nullable' => 'true',
465
+ );
466
+
467
+ $dispatchDate = array(
468
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
469
+ 'length' => 20,
470
+ 'comment' => 'Dispatch Date',
471
+ 'nullable' => 'true');
472
+
473
+ $deliveryDate = array(
474
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
475
+ 'length' => 20,
476
+ 'comment' => 'Expected Delivery',
477
+ 'nullable' => 'true');
478
+
479
+ $carrierNotice = array(
480
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
481
+ 'comment' => 'Shipperhq Carrier Notice',
482
+ 'nullable' => 'true',
483
+ );
484
+
485
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
486
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
487
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
488
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
489
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
490
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
491
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
492
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
493
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
494
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
495
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
496
+
497
+
498
+ } else {
499
+
500
+ $quoteAddressTable = $installer->getTable('sales/quote_address');
501
+ $quoteRateTable = $installer->getTable('sales/quote_address_shipping_rate');
502
+ $orderTable = $installer->getTable('sales/order');
503
+
504
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'is_checkout')){
505
+ $installer->run("
506
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD is_checkout smallint(1) unsigned NOT NULL default '0' COMMENT 'Shipperhq Shipper';
507
+ ");
508
+ }
509
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'carrier_type')){
510
+ $installer->run("
511
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
512
+ ");
513
+ }
514
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'dispatch_date')){
515
+ $installer->run("
516
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
517
+ ");
518
+ }
519
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'delivery_date')){
520
+ $installer->run("
521
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD delivery_date text COMMENT 'Shipperhq Expected Delivery Date';
522
+ ");
523
+ }
524
+
525
+
526
+
527
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'carrier_type')){
528
+ $installer->run("
529
+ ALTER IGNORE TABLE {$quoteRateTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
530
+ ");
531
+ }
532
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'dispatch_date')){
533
+ $installer->run("
534
+ ALTER IGNORE TABLE {$quoteRateTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
535
+ ");
536
+ }
537
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'delivery_date')){
538
+ $installer->run("
539
+ ALTER IGNORE TABLE {$quoteRateTable} ADD delivery_date text COMMENT 'Shipperhq Delivery Date';
540
+ ");
541
+ }
542
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'carrier_notice')){
543
+ $installer->run("
544
+ ALTER IGNORE TABLE {$quoteRateTable} ADD carrier_notice text COMMENT 'Shipperhq Carrier Notice';
545
+ ");
546
+ }
547
+
548
+
549
+
550
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'carrier_type')){
551
+ $installer->run("
552
+ ALTER IGNORE TABLE {$orderTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
553
+ ");
554
+ }
555
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'dispatch_date')){
556
+ $installer->run("
557
+ ALTER IGNORE TABLE {$orderTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
558
+ ");
559
+ }
560
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'delivery_date')){
561
+ $installer->run("
562
+ ALTER IGNORE TABLE {$orderTable} ADD delivery_date text COMMENT 'Shipperhq Delivery Date';
563
+ ");
564
+ }
565
+
566
+ }
567
+
568
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.14.php ADDED
@@ -0,0 +1,548 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $installer->run("
7
+ DROP TABLE IF EXISTS `{$installer->getTable('shipperhq_synchronize')}`;
8
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('shipperhq_synchronize')}` (
9
+ `synch_id` int(10) unsigned NOT NULL auto_increment COMMENT 'WebShopApps ShipperHQ',
10
+ `notification_id` int(10) unsigned NOT NULL default '0' COMMENT 'WebShopApps ShipperHQ',
11
+ `attribute_code` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
12
+ `attribute_type` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
13
+ `value` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
14
+ `status` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
15
+ `date_added` datetime NOT NULL COMMENT 'WebShopApps ShipperHQ',
16
+ PRIMARY KEY (`synch_id`)
17
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
18
+
19
+
20
+ select @entity_type_id:=entity_type_id from {$this->getTable('eav_entity_type')} where entity_type_code='catalog_product';
21
+
22
+ select @attribute_group_id:=attribute_group_id from {$this->getTable('eav_attribute_group')} where attribute_group_name='Shipping' and attribute_set_id = @attribute_set_id;
23
+
24
+ /* Shipping Group attribute for modules like i.e ProductMatrix */
25
+ insert ignore into {$this->getTable('eav_attribute')}
26
+ set entity_type_id = @entity_type_id,
27
+ attribute_code = 'shipperhq_shipping_group',
28
+ backend_type = 'varchar',
29
+ frontend_input = 'multiselect',
30
+ backend_model = 'eav/entity_attribute_backend_array',
31
+ is_required = 0,
32
+ is_user_defined = 1,
33
+ frontend_label = 'Shipping Group';
34
+
35
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_group';
36
+
37
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
38
+ set attribute_id = @attribute_id,
39
+ is_visible = 1,
40
+ used_in_product_listing = 0,
41
+ is_filterable_in_search = 0,
42
+ is_global = 0;
43
+
44
+
45
+ /* Warehouse attribute for modules like i.e Dropship */
46
+ insert ignore into {$this->getTable('eav_attribute')}
47
+ set entity_type_id = @entity_type_id,
48
+ attribute_code = 'shipperhq_warehouse',
49
+ backend_type = 'text',
50
+ frontend_input = 'multiselect',
51
+ backend_model = 'eav/entity_attribute_backend_array',
52
+ is_required = 0,
53
+ is_user_defined = 1,
54
+ frontend_label = 'Origin';
55
+
56
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_warehouse';
57
+
58
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
59
+ set attribute_id = @attribute_id,
60
+ is_visible = 1,
61
+ used_in_product_listing = 0,
62
+ is_filterable_in_search = 0,
63
+ is_global = 0;
64
+
65
+ /* Shipping Qty */
66
+ insert ignore into {$this->getTable('eav_attribute')}
67
+ set entity_type_id = @entity_type_id,
68
+ attribute_code = 'shipperhq_shipping_qty',
69
+ backend_type = 'int',
70
+ frontend_input = 'text',
71
+ is_required = 0,
72
+ is_user_defined = 1,
73
+ frontend_label = 'Shipping Qty';
74
+
75
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_qty';
76
+
77
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
78
+ set attribute_id = @attribute_id,
79
+ is_visible = 1,
80
+ used_in_product_listing = 0,
81
+ is_filterable_in_search = 0;
82
+
83
+ /* Shipping Price */
84
+ insert ignore into {$this->getTable('eav_attribute')}
85
+ set entity_type_id = @entity_type_id,
86
+ attribute_code = 'shipperhq_shipping_fee',
87
+ backend_type = 'decimal',
88
+ frontend_input = 'price',
89
+ is_required = 0,
90
+ is_user_defined = 1,
91
+ frontend_label = 'Shipping Fee';
92
+
93
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_fee';
94
+
95
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
96
+ set attribute_id = @attribute_id,
97
+ is_visible = 1,
98
+ used_in_product_listing = 0,
99
+ is_filterable_in_search = 0,
100
+ is_global = 0;
101
+
102
+ /* Additional Price */
103
+ insert ignore into {$this->getTable('eav_attribute')}
104
+ set entity_type_id = @entity_type_id,
105
+ attribute_code = 'shipperhq_additional_price',
106
+ backend_type = 'decimal',
107
+ frontend_input = 'price',
108
+ is_required = 0,
109
+ is_user_defined = 1,
110
+ frontend_label = 'Additional Price';
111
+
112
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_additional_price';
113
+
114
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
115
+ set attribute_id = @attribute_id,
116
+ is_visible = 1,
117
+ used_in_product_listing = 0,
118
+ is_filterable_in_search = 0;
119
+
120
+
121
+ /* freight class */
122
+ insert ignore into {$this->getTable('eav_attribute')}
123
+ set entity_type_id = @entity_type_id,
124
+ attribute_code = 'freight_class',
125
+ backend_type = 'int',
126
+ frontend_input = 'text',
127
+ is_required = 0,
128
+ is_user_defined = 1,
129
+ frontend_label = 'Freight Class';
130
+
131
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='freight_class';
132
+
133
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
134
+ set attribute_id = @attribute_id,
135
+ is_visible = 1,
136
+ used_in_product_listing = 0,
137
+ is_filterable_in_search = 0;
138
+
139
+ /* nmfc */
140
+ insert ignore into {$this->getTable('eav_attribute')}
141
+ set entity_type_id = @entity_type_id,
142
+ attribute_code = 'shipperhq_nmfc_class',
143
+ backend_type = 'text',
144
+ frontend_input = 'text',
145
+ is_required = 0,
146
+ is_user_defined = 1,
147
+ frontend_label = 'NMFC Class';
148
+
149
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_nmfc_class';
150
+
151
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
152
+ set attribute_id = @attribute_id,
153
+ is_visible = 1,
154
+ used_in_product_listing = 0,
155
+ is_filterable_in_search = 0;
156
+
157
+ /*Must Ship Freight*/
158
+ insert ignore into {$this->getTable('eav_attribute')}
159
+ set entity_type_id = @entity_type_id,
160
+ attribute_code = 'must_ship_freight',
161
+ backend_type = 'int',
162
+ frontend_input = 'boolean',
163
+ is_required = 0,
164
+ is_user_defined = 1,
165
+ frontend_label = 'Must ship freight';
166
+
167
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='must_ship_freight';
168
+
169
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
170
+ set attribute_id = @attribute_id,
171
+ is_visible = 1,
172
+ used_in_product_listing = 0,
173
+ is_filterable_in_search = 0;
174
+
175
+ /* Handling Price */
176
+ insert ignore into {$this->getTable('eav_attribute')}
177
+ set entity_type_id = @entity_type_id,
178
+ attribute_code = 'shipperhq_handling_fee',
179
+ backend_type = 'decimal',
180
+ frontend_input = 'price',
181
+ is_required = 0,
182
+ is_user_defined = 1,
183
+ frontend_label = 'Handling Fee';
184
+
185
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_handling_fee';
186
+
187
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
188
+ set attribute_id = @attribute_id,
189
+ is_visible = 1,
190
+ used_in_product_listing = 0,
191
+ is_filterable_in_search = 0;
192
+
193
+
194
+ /* Carrier Code */
195
+ insert ignore into {$this->getTable('eav_attribute')}
196
+ set entity_type_id = @entity_type_id,
197
+ attribute_code = 'shipperhq_carrier_code',
198
+ backend_type = 'text',
199
+ frontend_input = 'text',
200
+ is_required = 0,
201
+ is_user_defined = 1,
202
+ frontend_label = 'Carrier Code';
203
+
204
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_carrier_code';
205
+
206
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
207
+ set attribute_id = @attribute_id,
208
+ is_visible = 1,
209
+ used_in_product_listing = 0,
210
+ is_filterable_in_search = 0;
211
+
212
+
213
+ /* Volume Weight */
214
+ insert ignore into {$this->getTable('eav_attribute')}
215
+ set entity_type_id = @entity_type_id,
216
+ attribute_code = 'shipperhq_volume_weight',
217
+ backend_type = 'decimal',
218
+ frontend_input = 'text',
219
+ is_required = 0,
220
+ is_user_defined = 1,
221
+ frontend_label = 'Volume Weight';
222
+
223
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_volume_weight';
224
+
225
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
226
+ set attribute_id = @attribute_id,
227
+ is_visible = 1,
228
+ used_in_product_listing = 0,
229
+ is_filterable_in_search = 0;
230
+
231
+ /* Declared Value */
232
+ insert ignore into {$this->getTable('eav_attribute')}
233
+ set entity_type_id = @entity_type_id,
234
+ attribute_code = 'shipperhq_declared_value',
235
+ backend_type = 'decimal',
236
+ frontend_input = 'price',
237
+ is_required = 0,
238
+ is_user_defined = 1,
239
+ frontend_label = 'Declared Value',
240
+ note = 'The deemed cost of this product for customs & insurance purposes';
241
+
242
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_declared_value';
243
+
244
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
245
+ set attribute_id = @attribute_id,
246
+ is_visible = 1,
247
+ used_in_product_listing = 0,
248
+ is_filterable_in_search = 0;
249
+
250
+ /*Ship Separately*/
251
+ insert ignore into {$this->getTable('eav_attribute')}
252
+ set entity_type_id = @entity_type_id,
253
+ attribute_code = 'ship_separately',
254
+ backend_type = 'int',
255
+ frontend_input = 'boolean',
256
+ is_user_defined = 1,
257
+ is_required = 0,
258
+ frontend_label = 'Ship Separately';
259
+
260
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_separately';
261
+
262
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
263
+ set attribute_id = @attribute_id,
264
+ is_visible = 1,
265
+ used_in_product_listing = 0,
266
+ is_filterable_in_search = 0;
267
+
268
+ /*Dimensional Group*/
269
+ insert ignore into {$this->getTable('eav_attribute')}
270
+ set entity_type_id = @entity_type_id,
271
+ attribute_code = 'shipperhq_dim_group',
272
+ backend_type = 'varchar',
273
+ frontend_input = 'select',
274
+ backend_model = 'eav/entity_attribute_backend_array',
275
+ is_user_defined = 1,
276
+ is_required = 0,
277
+ frontend_label = 'ShipperHQ Dimensional Rule Group';
278
+
279
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_dim_group';
280
+
281
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
282
+ set attribute_id = @attribute_id,
283
+ is_visible = 1,
284
+ used_in_product_listing = 0,
285
+ is_filterable_in_search = 0;
286
+
287
+ /*Dimensional Ship Length*/
288
+ insert ignore into {$this->getTable('eav_attribute')}
289
+ set entity_type_id = @entity_type_id,
290
+ attribute_code = 'ship_length',
291
+ backend_type = 'decimal',
292
+ frontend_input = 'text',
293
+ is_required = 0,
294
+ is_user_defined = 1,
295
+ frontend_label = 'Dimension Length';
296
+
297
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_length';
298
+
299
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
300
+ set attribute_id = @attribute_id,
301
+ is_visible = 1,
302
+ used_in_product_listing = 0,
303
+ is_filterable_in_search = 0;
304
+
305
+
306
+ /*Dimensional Ship Width*/
307
+ insert ignore into {$this->getTable('eav_attribute')}
308
+ set entity_type_id = @entity_type_id,
309
+ attribute_code = 'ship_width',
310
+ backend_type = 'decimal',
311
+ frontend_input = 'text',
312
+ is_required = 0,
313
+ is_user_defined = 1,
314
+ frontend_label = 'Dimension Width';
315
+
316
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_width';
317
+
318
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
319
+ set attribute_id = @attribute_id,
320
+ is_visible = 1,
321
+ used_in_product_listing = 0,
322
+ is_filterable_in_search = 0;
323
+
324
+ /*Dimensional Ship Height*/
325
+ insert ignore into {$this->getTable('eav_attribute')}
326
+ set entity_type_id = @entity_type_id,
327
+ attribute_code = 'ship_height',
328
+ backend_type = 'decimal',
329
+ frontend_input = 'text',
330
+ is_required = 0,
331
+ is_user_defined = 1,
332
+ frontend_label = 'Dimension Height';
333
+
334
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_height';
335
+
336
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
337
+ set attribute_id = @attribute_id,
338
+ is_visible = 1,
339
+ used_in_product_listing = 0,
340
+ is_filterable_in_search = 0;
341
+
342
+ /*Dimensional Possible Ship Boxes*/
343
+ insert ignore into {$this->getTable('eav_attribute')}
344
+ set entity_type_id = @entity_type_id,
345
+ attribute_code = 'shipperhq_poss_boxes',
346
+ backend_type = 'varchar',
347
+ backend_model = 'eav/entity_attribute_backend_array',
348
+ frontend_input = 'multiselect',
349
+ is_required = 0,
350
+ is_user_defined = 1,
351
+ frontend_label = 'Possible Packing Boxes';
352
+
353
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_poss_boxes';
354
+
355
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
356
+ set attribute_id = @attribute_id,
357
+ is_visible = 1,
358
+ used_in_product_listing = 0,
359
+ is_filterable_in_search = 0;
360
+
361
+ /*Dimensional Ship Box Tolerance */
362
+ insert ignore into {$this->getTable('eav_attribute')}
363
+ set entity_type_id = @entity_type_id,
364
+ attribute_code = 'ship_box_tolerance',
365
+ backend_type = 'int',
366
+ frontend_input = 'text',
367
+ is_user_defined = 1,
368
+ is_required = 0,
369
+ note = 'Note: Ignore if unsure',
370
+ frontend_label = 'Box Tolerance';
371
+
372
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_box_tolerance';
373
+
374
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
375
+ set attribute_id = @attribute_id,
376
+ is_visible = 1,
377
+ used_in_product_listing = 0,
378
+ is_filterable_in_search = 0;
379
+ ");
380
+
381
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
382
+
383
+ $attributeSetArr = $installer->getConnection()->fetchAll("SELECT attribute_set_id FROM {$this->getTable('eav_attribute_set')} WHERE entity_type_id={$entityTypeId}");
384
+
385
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
386
+ $dimAttributeCodes = array('ship_separately' => '2',
387
+ 'shipperhq_dim_group' => '1',
388
+ 'shipperhq_volume_weight' => '9',
389
+ 'ship_length' => '10',
390
+ 'ship_width' => '11',
391
+ 'ship_height' => '12',
392
+ 'shipperhq_poss_boxes' => '20',
393
+ 'ship_box_tolerance' => '22',
394
+ 'shipperhq_declared_value' => '25'
395
+ );
396
+ $freightAttributeCodes = array(
397
+ 'freight_class' => '1',
398
+ 'must_ship_freight' =>'10'
399
+ );
400
+
401
+ foreach ($attributeSetArr as $attr) {
402
+ $attributeSetId = $attr['attribute_set_id'];
403
+
404
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
405
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
406
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Freight Shipping', '101');
407
+
408
+
409
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
410
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
411
+ $freightAttGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Freight Shipping');
412
+
413
+ foreach($stdAttributeCodes as $code => $sort) {
414
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
415
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
416
+ }
417
+
418
+ foreach($dimAttributeCodes as $code => $sort) {
419
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
420
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
421
+ }
422
+
423
+ foreach($freightAttributeCodes as $code => $sort) {
424
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
425
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $freightAttGroupId, $attributeId, $sort);
426
+ }
427
+ };
428
+
429
+
430
+
431
+ if (Mage::helper('wsalogger')->getNewVersion() > 10) {
432
+
433
+
434
+ $isCheckout = array(
435
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
436
+ 'comment' => 'Shipperhq Shipper',
437
+ 'nullable' => 'false',
438
+ 'default' => '0'
439
+ );
440
+
441
+ $carrierType = array(
442
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
443
+ 'comment' => 'Shipperhq Carrier Type',
444
+ 'nullable' => 'true',
445
+ );
446
+
447
+ $dispatchDate = array(
448
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
449
+ 'length' => 20,
450
+ 'comment' => 'Dispatch Date',
451
+ 'nullable' => 'true');
452
+
453
+ $deliveryDate = array(
454
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
455
+ 'length' => 20,
456
+ 'comment' => 'Expected Delivery',
457
+ 'nullable' => 'true');
458
+
459
+ $carrierNotice = array(
460
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
461
+ 'comment' => 'Shipperhq Carrier Notice',
462
+ 'nullable' => 'true',
463
+ );
464
+
465
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
466
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
467
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
468
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
469
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
470
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
471
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
472
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
473
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
474
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
475
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
476
+
477
+
478
+ } else {
479
+
480
+ $quoteAddressTable = $installer->getTable('sales/quote_address');
481
+ $quoteRateTable = $installer->getTable('sales/quote_address_shipping_rate');
482
+ $orderTable = $installer->getTable('sales/order');
483
+
484
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'is_checkout')){
485
+ $installer->run("
486
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD is_checkout smallint(1) unsigned NOT NULL default '0' COMMENT 'Shipperhq Shipper';
487
+ ");
488
+ }
489
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'carrier_type')){
490
+ $installer->run("
491
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
492
+ ");
493
+ }
494
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'dispatch_date')){
495
+ $installer->run("
496
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
497
+ ");
498
+ }
499
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'delivery_date')){
500
+ $installer->run("
501
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD delivery_date text COMMENT 'Shipperhq Expected Delivery Date';
502
+ ");
503
+ }
504
+
505
+
506
+
507
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'carrier_type')){
508
+ $installer->run("
509
+ ALTER IGNORE TABLE {$quoteRateTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
510
+ ");
511
+ }
512
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'dispatch_date')){
513
+ $installer->run("
514
+ ALTER IGNORE TABLE {$quoteRateTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
515
+ ");
516
+ }
517
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'delivery_date')){
518
+ $installer->run("
519
+ ALTER IGNORE TABLE {$quoteRateTable} ADD delivery_date text COMMENT 'Shipperhq Delivery Date';
520
+ ");
521
+ }
522
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'carrier_notice')){
523
+ $installer->run("
524
+ ALTER IGNORE TABLE {$quoteRateTable} ADD carrier_notice text COMMENT 'Shipperhq Carrier Notice';
525
+ ");
526
+ }
527
+
528
+
529
+
530
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'carrier_type')){
531
+ $installer->run("
532
+ ALTER IGNORE TABLE {$orderTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
533
+ ");
534
+ }
535
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'dispatch_date')){
536
+ $installer->run("
537
+ ALTER IGNORE TABLE {$orderTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
538
+ ");
539
+ }
540
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'delivery_date')){
541
+ $installer->run("
542
+ ALTER IGNORE TABLE {$orderTable} ADD delivery_date text COMMENT 'Shipperhq Delivery Date';
543
+ ");
544
+ }
545
+
546
+ }
547
+
548
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.15.php ADDED
@@ -0,0 +1,567 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $installer->run("
7
+ DROP TABLE IF EXISTS `{$installer->getTable('shipperhq_synchronize')}`;
8
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('shipperhq_synchronize')}` (
9
+ `synch_id` int(10) unsigned NOT NULL auto_increment COMMENT 'WebShopApps ShipperHQ',
10
+ `notification_id` int(10) unsigned NOT NULL default '0' COMMENT 'WebShopApps ShipperHQ',
11
+ `attribute_code` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
12
+ `attribute_type` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
13
+ `value` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
14
+ `status` varchar(255) NOT NULL COMMENT 'WebShopApps ShipperHQ',
15
+ `date_added` datetime NOT NULL COMMENT 'WebShopApps ShipperHQ',
16
+ PRIMARY KEY (`synch_id`)
17
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
18
+
19
+
20
+ select @entity_type_id:=entity_type_id from {$this->getTable('eav_entity_type')} where entity_type_code='catalog_product';
21
+
22
+ select @attribute_group_id:=attribute_group_id from {$this->getTable('eav_attribute_group')} where attribute_group_name='Shipping' and attribute_set_id = @attribute_set_id;
23
+
24
+ /* Shipping Group attribute for modules like i.e ProductMatrix */
25
+ insert ignore into {$this->getTable('eav_attribute')}
26
+ set entity_type_id = @entity_type_id,
27
+ attribute_code = 'shipperhq_shipping_group',
28
+ backend_type = 'varchar',
29
+ frontend_input = 'multiselect',
30
+ backend_model = 'eav/entity_attribute_backend_array',
31
+ is_required = 0,
32
+ is_user_defined = 1,
33
+ frontend_label = 'Shipping Group';
34
+
35
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_group';
36
+
37
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
38
+ set attribute_id = @attribute_id,
39
+ is_visible = 1,
40
+ used_in_product_listing = 0,
41
+ is_filterable_in_search = 0,
42
+ is_global = 0;
43
+
44
+
45
+ /* Warehouse attribute for modules like i.e Dropship */
46
+ insert ignore into {$this->getTable('eav_attribute')}
47
+ set entity_type_id = @entity_type_id,
48
+ attribute_code = 'shipperhq_warehouse',
49
+ backend_type = 'text',
50
+ frontend_input = 'multiselect',
51
+ backend_model = 'eav/entity_attribute_backend_array',
52
+ is_required = 0,
53
+ is_user_defined = 1,
54
+ frontend_label = 'Origin';
55
+
56
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_warehouse';
57
+
58
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
59
+ set attribute_id = @attribute_id,
60
+ is_visible = 1,
61
+ used_in_product_listing = 0,
62
+ is_filterable_in_search = 0,
63
+ is_global = 0;
64
+
65
+ /* Shipping Qty */
66
+ insert ignore into {$this->getTable('eav_attribute')}
67
+ set entity_type_id = @entity_type_id,
68
+ attribute_code = 'shipperhq_shipping_qty',
69
+ backend_type = 'int',
70
+ frontend_input = 'text',
71
+ is_required = 0,
72
+ is_user_defined = 1,
73
+ frontend_label = 'Shipping Qty';
74
+
75
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_qty';
76
+
77
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
78
+ set attribute_id = @attribute_id,
79
+ is_visible = 1,
80
+ used_in_product_listing = 0,
81
+ is_filterable_in_search = 0;
82
+
83
+ /* Shipping Price */
84
+ insert ignore into {$this->getTable('eav_attribute')}
85
+ set entity_type_id = @entity_type_id,
86
+ attribute_code = 'shipperhq_shipping_fee',
87
+ backend_type = 'decimal',
88
+ frontend_input = 'price',
89
+ is_required = 0,
90
+ is_user_defined = 1,
91
+ frontend_label = 'Shipping Fee';
92
+
93
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_shipping_fee';
94
+
95
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
96
+ set attribute_id = @attribute_id,
97
+ is_visible = 1,
98
+ used_in_product_listing = 0,
99
+ is_filterable_in_search = 0,
100
+ is_global = 0;
101
+
102
+ /* Additional Price */
103
+ insert ignore into {$this->getTable('eav_attribute')}
104
+ set entity_type_id = @entity_type_id,
105
+ attribute_code = 'shipperhq_additional_price',
106
+ backend_type = 'decimal',
107
+ frontend_input = 'price',
108
+ is_required = 0,
109
+ is_user_defined = 1,
110
+ frontend_label = 'Additional Price';
111
+
112
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_additional_price';
113
+
114
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
115
+ set attribute_id = @attribute_id,
116
+ is_visible = 1,
117
+ used_in_product_listing = 0,
118
+ is_filterable_in_search = 0;
119
+
120
+
121
+ /* freight class */
122
+ insert ignore into {$this->getTable('eav_attribute')}
123
+ set entity_type_id = @entity_type_id,
124
+ attribute_code = 'freight_class',
125
+ backend_type = 'int',
126
+ frontend_input = 'text',
127
+ is_required = 0,
128
+ is_user_defined = 1,
129
+ frontend_label = 'Freight Class';
130
+
131
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='freight_class';
132
+
133
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
134
+ set attribute_id = @attribute_id,
135
+ is_visible = 1,
136
+ used_in_product_listing = 0,
137
+ is_filterable_in_search = 0;
138
+
139
+ /* nmfc */
140
+ insert ignore into {$this->getTable('eav_attribute')}
141
+ set entity_type_id = @entity_type_id,
142
+ attribute_code = 'shipperhq_nmfc_class',
143
+ backend_type = 'text',
144
+ frontend_input = 'text',
145
+ is_required = 0,
146
+ is_user_defined = 1,
147
+ frontend_label = 'NMFC Class';
148
+
149
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_nmfc_class';
150
+
151
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
152
+ set attribute_id = @attribute_id,
153
+ is_visible = 1,
154
+ used_in_product_listing = 0,
155
+ is_filterable_in_search = 0;
156
+
157
+ /*Must Ship Freight*/
158
+ insert ignore into {$this->getTable('eav_attribute')}
159
+ set entity_type_id = @entity_type_id,
160
+ attribute_code = 'must_ship_freight',
161
+ backend_type = 'int',
162
+ frontend_input = 'boolean',
163
+ is_required = 0,
164
+ is_user_defined = 1,
165
+ frontend_label = 'Must ship freight';
166
+
167
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='must_ship_freight';
168
+
169
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
170
+ set attribute_id = @attribute_id,
171
+ is_visible = 1,
172
+ used_in_product_listing = 0,
173
+ is_filterable_in_search = 0;
174
+
175
+ /* Handling Price */
176
+ insert ignore into {$this->getTable('eav_attribute')}
177
+ set entity_type_id = @entity_type_id,
178
+ attribute_code = 'shipperhq_handling_fee',
179
+ backend_type = 'decimal',
180
+ frontend_input = 'price',
181
+ is_required = 0,
182
+ is_user_defined = 1,
183
+ frontend_label = 'Handling Fee';
184
+
185
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_handling_fee';
186
+
187
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
188
+ set attribute_id = @attribute_id,
189
+ is_visible = 1,
190
+ used_in_product_listing = 0,
191
+ is_filterable_in_search = 0;
192
+
193
+
194
+ /* Carrier Code */
195
+ insert ignore into {$this->getTable('eav_attribute')}
196
+ set entity_type_id = @entity_type_id,
197
+ attribute_code = 'shipperhq_carrier_code',
198
+ backend_type = 'text',
199
+ frontend_input = 'text',
200
+ is_required = 0,
201
+ is_user_defined = 1,
202
+ frontend_label = 'Carrier Code';
203
+
204
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_carrier_code';
205
+
206
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
207
+ set attribute_id = @attribute_id,
208
+ is_visible = 1,
209
+ used_in_product_listing = 0,
210
+ is_filterable_in_search = 0;
211
+
212
+
213
+ /* Volume Weight */
214
+ insert ignore into {$this->getTable('eav_attribute')}
215
+ set entity_type_id = @entity_type_id,
216
+ attribute_code = 'shipperhq_volume_weight',
217
+ backend_type = 'decimal',
218
+ frontend_input = 'text',
219
+ is_required = 0,
220
+ is_user_defined = 1,
221
+ frontend_label = 'Volume Weight';
222
+
223
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_volume_weight';
224
+
225
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
226
+ set attribute_id = @attribute_id,
227
+ is_visible = 1,
228
+ used_in_product_listing = 0,
229
+ is_filterable_in_search = 0;
230
+
231
+ /* Declared Value */
232
+ insert ignore into {$this->getTable('eav_attribute')}
233
+ set entity_type_id = @entity_type_id,
234
+ attribute_code = 'shipperhq_declared_value',
235
+ backend_type = 'decimal',
236
+ frontend_input = 'price',
237
+ is_required = 0,
238
+ is_user_defined = 1,
239
+ frontend_label = 'Declared Value',
240
+ note = 'The deemed cost of this product for customs & insurance purposes';
241
+
242
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_declared_value';
243
+
244
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
245
+ set attribute_id = @attribute_id,
246
+ is_visible = 1,
247
+ used_in_product_listing = 0,
248
+ is_filterable_in_search = 0;
249
+
250
+ /*Ship Separately*/
251
+ insert ignore into {$this->getTable('eav_attribute')}
252
+ set entity_type_id = @entity_type_id,
253
+ attribute_code = 'ship_separately',
254
+ backend_type = 'int',
255
+ frontend_input = 'boolean',
256
+ is_user_defined = 1,
257
+ is_required = 0,
258
+ frontend_label = 'Ship Separately';
259
+
260
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_separately';
261
+
262
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
263
+ set attribute_id = @attribute_id,
264
+ is_visible = 1,
265
+ used_in_product_listing = 0,
266
+ is_filterable_in_search = 0;
267
+
268
+ /*Dimensional Group*/
269
+ insert ignore into {$this->getTable('eav_attribute')}
270
+ set entity_type_id = @entity_type_id,
271
+ attribute_code = 'shipperhq_dim_group',
272
+ backend_type = 'varchar',
273
+ frontend_input = 'select',
274
+ backend_model = 'eav/entity_attribute_backend_array',
275
+ is_user_defined = 1,
276
+ is_required = 0,
277
+ frontend_label = 'ShipperHQ Dimensional Rule Group';
278
+
279
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_dim_group';
280
+
281
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
282
+ set attribute_id = @attribute_id,
283
+ is_visible = 1,
284
+ used_in_product_listing = 0,
285
+ is_filterable_in_search = 0;
286
+
287
+ /*Dimensional Ship Length*/
288
+ insert ignore into {$this->getTable('eav_attribute')}
289
+ set entity_type_id = @entity_type_id,
290
+ attribute_code = 'ship_length',
291
+ backend_type = 'decimal',
292
+ frontend_input = 'text',
293
+ is_required = 0,
294
+ is_user_defined = 1,
295
+ frontend_label = 'Dimension Length';
296
+
297
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_length';
298
+
299
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
300
+ set attribute_id = @attribute_id,
301
+ is_visible = 1,
302
+ used_in_product_listing = 0,
303
+ is_filterable_in_search = 0;
304
+
305
+
306
+ /*Dimensional Ship Width*/
307
+ insert ignore into {$this->getTable('eav_attribute')}
308
+ set entity_type_id = @entity_type_id,
309
+ attribute_code = 'ship_width',
310
+ backend_type = 'decimal',
311
+ frontend_input = 'text',
312
+ is_required = 0,
313
+ is_user_defined = 1,
314
+ frontend_label = 'Dimension Width';
315
+
316
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_width';
317
+
318
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
319
+ set attribute_id = @attribute_id,
320
+ is_visible = 1,
321
+ used_in_product_listing = 0,
322
+ is_filterable_in_search = 0;
323
+
324
+ /*Dimensional Ship Height*/
325
+ insert ignore into {$this->getTable('eav_attribute')}
326
+ set entity_type_id = @entity_type_id,
327
+ attribute_code = 'ship_height',
328
+ backend_type = 'decimal',
329
+ frontend_input = 'text',
330
+ is_required = 0,
331
+ is_user_defined = 1,
332
+ frontend_label = 'Dimension Height';
333
+
334
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_height';
335
+
336
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
337
+ set attribute_id = @attribute_id,
338
+ is_visible = 1,
339
+ used_in_product_listing = 0,
340
+ is_filterable_in_search = 0;
341
+
342
+ /*Dimensional Possible Ship Boxes*/
343
+ insert ignore into {$this->getTable('eav_attribute')}
344
+ set entity_type_id = @entity_type_id,
345
+ attribute_code = 'shipperhq_poss_boxes',
346
+ backend_type = 'varchar',
347
+ backend_model = 'eav/entity_attribute_backend_array',
348
+ frontend_input = 'multiselect',
349
+ is_required = 0,
350
+ is_user_defined = 1,
351
+ frontend_label = 'Possible Packing Boxes';
352
+
353
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='shipperhq_poss_boxes';
354
+
355
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
356
+ set attribute_id = @attribute_id,
357
+ is_visible = 1,
358
+ used_in_product_listing = 0,
359
+ is_filterable_in_search = 0;
360
+
361
+ /*Dimensional Ship Box Tolerance */
362
+ insert ignore into {$this->getTable('eav_attribute')}
363
+ set entity_type_id = @entity_type_id,
364
+ attribute_code = 'ship_box_tolerance',
365
+ backend_type = 'int',
366
+ frontend_input = 'text',
367
+ is_user_defined = 1,
368
+ is_required = 0,
369
+ note = 'Note: Ignore if unsure',
370
+ frontend_label = 'Box Tolerance';
371
+
372
+ select @attribute_id:=attribute_id from {$this->getTable('eav_attribute')} where attribute_code='ship_box_tolerance';
373
+
374
+ insert ignore into {$this->getTable('catalog_eav_attribute')}
375
+ set attribute_id = @attribute_id,
376
+ is_visible = 1,
377
+ used_in_product_listing = 0,
378
+ is_filterable_in_search = 0;
379
+ ");
380
+
381
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
382
+
383
+ $attributeSetArr = $installer->getConnection()->fetchAll("SELECT attribute_set_id FROM {$this->getTable('eav_attribute_set')} WHERE entity_type_id={$entityTypeId}");
384
+
385
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
386
+ $dimAttributeCodes = array('ship_separately' => '2',
387
+ 'shipperhq_dim_group' => '1',
388
+ 'shipperhq_volume_weight' => '9',
389
+ 'ship_length' => '10',
390
+ 'ship_width' => '11',
391
+ 'ship_height' => '12',
392
+ 'shipperhq_poss_boxes' => '20',
393
+ 'ship_box_tolerance' => '22',
394
+ 'shipperhq_declared_value' => '25'
395
+ );
396
+ $freightAttributeCodes = array(
397
+ 'freight_class' => '1',
398
+ 'must_ship_freight' =>'10'
399
+ );
400
+
401
+ foreach ($attributeSetArr as $attr) {
402
+ $attributeSetId = $attr['attribute_set_id'];
403
+
404
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
405
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
406
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Freight Shipping', '101');
407
+
408
+
409
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
410
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
411
+ $freightAttGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Freight Shipping');
412
+
413
+ foreach($stdAttributeCodes as $code => $sort) {
414
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
415
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
416
+ }
417
+
418
+ foreach($dimAttributeCodes as $code => $sort) {
419
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
420
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
421
+ }
422
+
423
+ foreach($freightAttributeCodes as $code => $sort) {
424
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
425
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $freightAttGroupId, $attributeId, $sort);
426
+ }
427
+ };
428
+
429
+
430
+
431
+ if (Mage::helper('wsalogger')->getNewVersion() > 10) {
432
+
433
+
434
+ $isCheckout = array(
435
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
436
+ 'comment' => 'Shipperhq Shipper',
437
+ 'nullable' => 'false',
438
+ 'default' => '0'
439
+ );
440
+
441
+ $carrierType = array(
442
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
443
+ 'comment' => 'Shipperhq Carrier Type',
444
+ 'nullable' => 'true',
445
+ );
446
+
447
+ $dispatchDate = array(
448
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
449
+ 'length' => 20,
450
+ 'comment' => 'Dispatch Date',
451
+ 'nullable' => 'true');
452
+
453
+ $deliveryDate = array(
454
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
455
+ 'length' => 20,
456
+ 'comment' => 'Expected Delivery',
457
+ 'nullable' => 'true');
458
+
459
+ $carrierNotice = array(
460
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
461
+ 'comment' => 'Shipperhq Carrier Notice',
462
+ 'nullable' => 'true',
463
+ );
464
+
465
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
466
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
467
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
468
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
469
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
470
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
471
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
472
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
473
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
474
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
475
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
476
+
477
+
478
+ } else {
479
+
480
+ $quoteAddressTable = $installer->getTable('sales/quote_address');
481
+ $quoteRateTable = $installer->getTable('sales/quote_address_shipping_rate');
482
+ $orderTable = $installer->getTable('sales/order');
483
+
484
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'is_checkout')){
485
+ $installer->run("
486
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD is_checkout smallint(1) unsigned NOT NULL default '0' COMMENT 'Shipperhq Shipper';
487
+ ");
488
+ }
489
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'carrier_type')){
490
+ $installer->run("
491
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
492
+ ");
493
+ }
494
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'dispatch_date')){
495
+ $installer->run("
496
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
497
+ ");
498
+ }
499
+ if(!$installer->getConnection()->tableColumnExists($quoteAddressTable, 'delivery_date')){
500
+ $installer->run("
501
+ ALTER IGNORE TABLE {$quoteAddressTable} ADD delivery_date text COMMENT 'Shipperhq Expected Delivery Date';
502
+ ");
503
+ }
504
+
505
+
506
+
507
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'carrier_type')){
508
+ $installer->run("
509
+ ALTER IGNORE TABLE {$quoteRateTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
510
+ ");
511
+ }
512
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'dispatch_date')){
513
+ $installer->run("
514
+ ALTER IGNORE TABLE {$quoteRateTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
515
+ ");
516
+ }
517
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'delivery_date')){
518
+ $installer->run("
519
+ ALTER IGNORE TABLE {$quoteRateTable} ADD delivery_date text COMMENT 'Shipperhq Delivery Date';
520
+ ");
521
+ }
522
+ if(!$installer->getConnection()->tableColumnExists($quoteRateTable, 'carrier_notice')){
523
+ $installer->run("
524
+ ALTER IGNORE TABLE {$quoteRateTable} ADD carrier_notice text COMMENT 'Shipperhq Carrier Notice';
525
+ ");
526
+ }
527
+
528
+
529
+
530
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'carrier_type')){
531
+ $installer->run("
532
+ ALTER IGNORE TABLE {$orderTable} ADD carrier_type text COMMENT 'Shipperhq Carrier Type';
533
+ ");
534
+ }
535
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'dispatch_date')){
536
+ $installer->run("
537
+ ALTER IGNORE TABLE {$orderTable} ADD dispatch_date text COMMENT 'Shipperhq Dispatch Date';
538
+ ");
539
+ }
540
+ if(!$installer->getConnection()->tableColumnExists($orderTable, 'delivery_date')){
541
+ $installer->run("
542
+ ALTER IGNORE TABLE {$orderTable} ADD delivery_date text COMMENT 'Shipperhq Delivery Date';
543
+ ");
544
+ }
545
+
546
+ }
547
+
548
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/storage'));
549
+
550
+ $table
551
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
552
+ 'primary' => true,
553
+ 'nullable' => false,
554
+ 'unsigned' => true
555
+ ))
556
+ ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '512k', array('nullable' => false))
557
+ ->addForeignKey(
558
+ $this->getFkName('shipperhq_shipper/storage', 'quote_id', 'sales/quote', 'entity_id'),
559
+ 'quote_id',
560
+ $this->getTable('sales/quote'),
561
+ 'entity_id',
562
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
563
+ )
564
+ ;
565
+ $this->getConnection()->createTable($table);
566
+
567
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.16.php ADDED
@@ -0,0 +1,461 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/attributeupdate'))) {
8
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/attributeupdate'));
9
+
10
+ $table
11
+ ->addColumn('synch_id', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array(
12
+ 'primary' => true,
13
+ 'nullable' => false,
14
+ 'unsigned' => true,
15
+ 'auto_increment' => true
16
+ ))
17
+ ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 0, array(
18
+ 'nullable' => false,
19
+ 'unsigned' => true,
20
+ ))
21
+ ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
22
+ 'nullable' => false,
23
+ ))
24
+ ->addColumn('attribute_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
25
+ 'nullable' => false,
26
+ ))
27
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
28
+ 'nullable' => false,
29
+ ))
30
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
31
+ 'nullable' => false,
32
+ ))
33
+ ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
34
+ 'nullable' => false,
35
+ ))
36
+ ;
37
+ $this->getConnection()->createTable($table);
38
+ }
39
+
40
+ /* ------ shipperhq_shipping_group -------- */
41
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_group', array(
42
+ 'type' => 'varchar',
43
+ 'backend' => 'eav/entity_attribute_backend_array',
44
+ 'input' => 'multiselect',
45
+ 'label' => 'Shipping Group',
46
+ 'global' => false,
47
+ 'visible' => 1,
48
+ 'required' => 0,
49
+ 'visible_on_front' => 0,
50
+ 'is_html_allowed_on_front' => 0,
51
+ 'searchable' => 0,
52
+ 'filterable' => 0,
53
+ 'comparable' => 0,
54
+ 'unique' => false,
55
+ 'user_defined' => true,
56
+ 'is_user_defined' => false,
57
+ 'used_in_product_listing' => false
58
+ ));
59
+
60
+ /* ------ shipperhq_warehouse -------- */
61
+ $this->addAttribute('catalog_product', 'shipperhq_warehouse', array(
62
+ 'type' => 'text',
63
+ 'backend' => 'eav/entity_attribute_backend_array',
64
+ 'input' => 'multiselect',
65
+ 'label' => 'Origin',
66
+ 'global' => false,
67
+ 'visible' => 1,
68
+ 'required' => 0,
69
+ 'visible_on_front' => 0,
70
+ 'is_html_allowed_on_front' => 0,
71
+ 'searchable' => 0,
72
+ 'filterable' => 0,
73
+ 'comparable' => 0,
74
+ 'unique' => false,
75
+ 'user_defined' => true,
76
+ 'is_user_defined' => true,
77
+ 'used_in_product_listing' => false
78
+ ));
79
+
80
+ /* ------ shipperhq_shipping_qty -------- */
81
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_qty', array(
82
+ 'type' => 'int',
83
+ 'input' => 'text',
84
+ 'label' => 'Shipping Qty',
85
+ 'global' => false,
86
+ 'visible' => 1,
87
+ 'required' => 0,
88
+ 'visible_on_front' => 0,
89
+ 'is_html_allowed_on_front' => 0,
90
+ 'searchable' => 0,
91
+ 'filterable' => 0,
92
+ 'comparable' => 0,
93
+ 'unique' => false,
94
+ 'user_defined' => true,
95
+ 'is_user_defined' => true,
96
+ 'used_in_product_listing' => false
97
+ ));
98
+
99
+ /* ------ shipperhq_shipping_fee -------- */
100
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_fee', array(
101
+ 'type' => 'decimal',
102
+ 'input' => 'price',
103
+ 'label' => 'Shipping Fee',
104
+ 'global' => false,
105
+ 'visible' => 1,
106
+ 'required' => 0,
107
+ 'visible_on_front' => 0,
108
+ 'is_html_allowed_on_front' => 0,
109
+ 'searchable' => 0,
110
+ 'filterable' => 0,
111
+ 'comparable' => 0,
112
+ 'unique' => false,
113
+ 'user_defined' => true,
114
+ 'is_user_defined' => true,
115
+ 'used_in_product_listing' => false
116
+ ));
117
+
118
+ /* ------ shipperhq_additional_price -------- */
119
+ $this->addAttribute('catalog_product', 'shipperhq_additional_price', array(
120
+ 'type' => 'decimal',
121
+ 'input' => 'price',
122
+ 'label' => 'Additional Price',
123
+ 'global' => false,
124
+ 'visible' => 1,
125
+ 'required' => 0,
126
+ 'visible_on_front' => 0,
127
+ 'is_html_allowed_on_front' => 0,
128
+ 'searchable' => 0,
129
+ 'filterable' => 0,
130
+ 'comparable' => 0,
131
+ 'unique' => false,
132
+ 'user_defined' => true,
133
+ 'is_user_defined' => true,
134
+ 'used_in_product_listing' => false
135
+ ));
136
+
137
+ /* ------ shipperhq_handling_fee -------- */
138
+ $this->addAttribute('catalog_product', 'shipperhq_handling_fee', array(
139
+ 'type' => 'decimal',
140
+ 'input' => 'price',
141
+ 'label' => 'Handling Fee',
142
+ 'global' => false,
143
+ 'visible' => 1,
144
+ 'required' => 0,
145
+ 'visible_on_front' => 0,
146
+ 'is_html_allowed_on_front' => 0,
147
+ 'searchable' => 0,
148
+ 'filterable' => 0,
149
+ 'comparable' => 0,
150
+ 'unique' => false,
151
+ 'user_defined' => true,
152
+ 'is_user_defined' => true,
153
+ 'used_in_product_listing' => false
154
+ ));
155
+
156
+ /* ------ shipperhq_carrier_code -------- */
157
+ $this->addAttribute('catalog_product', 'shipperhq_carrier_code', array(
158
+ 'type' => 'text',
159
+ 'input' => 'text',
160
+ 'label' => 'Carrier Code',
161
+ 'global' => false,
162
+ 'visible' => 1,
163
+ 'required' => 0,
164
+ 'visible_on_front' => 0,
165
+ 'is_html_allowed_on_front' => 0,
166
+ 'searchable' => 0,
167
+ 'filterable' => 0,
168
+ 'comparable' => 0,
169
+ 'unique' => false,
170
+ 'user_defined' => true,
171
+ 'is_user_defined' => true,
172
+ 'used_in_product_listing' => false
173
+ ));
174
+
175
+ /* ------ shipperhq_volume_weight -------- */
176
+ $this->addAttribute('catalog_product', 'shipperhq_volume_weight', array(
177
+ 'type' => 'decimal',
178
+ 'input' => 'text',
179
+ 'label' => 'Volume Weight',
180
+ 'global' => false,
181
+ 'visible' => 1,
182
+ 'required' => 0,
183
+ 'visible_on_front' => 0,
184
+ 'is_html_allowed_on_front' => 0,
185
+ 'searchable' => 0,
186
+ 'filterable' => 0,
187
+ 'comparable' => 0,
188
+ 'unique' => false,
189
+ 'user_defined' => true,
190
+ 'is_user_defined' => true,
191
+ 'used_in_product_listing' => false
192
+ ));
193
+
194
+ /* ------ shipperhq_declared_value -------- */
195
+ $this->addAttribute('catalog_product', 'shipperhq_declared_value', array(
196
+ 'type' => 'decimal',
197
+ 'input' => 'price',
198
+ 'label' => 'Declared Value',
199
+ 'global' => false,
200
+ 'visible' => 1,
201
+ 'required' => 0,
202
+ 'visible_on_front' => 0,
203
+ 'is_html_allowed_on_front' => 0,
204
+ 'searchable' => 0,
205
+ 'filterable' => 0,
206
+ 'comparable' => 0,
207
+ 'unique' => false,
208
+ 'user_defined' => true,
209
+ 'is_user_defined' => true,
210
+ 'used_in_product_listing' => false,
211
+ 'note' => 'The deemed cost of this product for customs & insurance purposes'
212
+ ));
213
+
214
+ /* ------ ship_separately -------- */
215
+ $this->addAttribute('catalog_product', 'ship_separately', array(
216
+ 'type' => 'int',
217
+ 'input' => 'boolean',
218
+ 'label' => 'Ship Separately',
219
+ 'global' => false,
220
+ 'visible' => 1,
221
+ 'required' => 0,
222
+ 'visible_on_front' => 0,
223
+ 'is_html_allowed_on_front' => 0,
224
+ 'searchable' => 0,
225
+ 'filterable' => 0,
226
+ 'comparable' => 0,
227
+ 'unique' => false,
228
+ 'user_defined' => true,
229
+ 'is_user_defined' => true,
230
+ 'used_in_product_listing' => false
231
+ ));
232
+
233
+ /* ------ shipperhq_dim_group -------- */
234
+ $this->addAttribute('catalog_product', 'shipperhq_dim_group', array(
235
+ 'type' => 'varchar',
236
+ 'input' => 'select',
237
+ 'label' => 'ShipperHQ Dimensional Rule Group',
238
+ 'backend' => 'eav/entity_attribute_backend_array',
239
+ 'global' => false,
240
+ 'visible' => 1,
241
+ 'required' => 0,
242
+ 'visible_on_front' => 0,
243
+ 'is_html_allowed_on_front' => 0,
244
+ 'searchable' => 0,
245
+ 'filterable' => 0,
246
+ 'comparable' => 0,
247
+ 'unique' => false,
248
+ 'user_defined' => true,
249
+ 'is_user_defined' => true,
250
+ 'used_in_product_listing' => false
251
+ ));
252
+
253
+ /* ------ ship_length -------- */
254
+ $this->addAttribute('catalog_product', 'ship_length', array(
255
+ 'type' => 'decimal',
256
+ 'input' => 'text',
257
+ 'label' => 'Dimension Length',
258
+ 'global' => false,
259
+ 'visible' => 1,
260
+ 'required' => 0,
261
+ 'visible_on_front' => 0,
262
+ 'is_html_allowed_on_front' => 0,
263
+ 'searchable' => 0,
264
+ 'filterable' => 0,
265
+ 'comparable' => 0,
266
+ 'unique' => false,
267
+ 'user_defined' => true,
268
+ 'is_user_defined' => true,
269
+ 'used_in_product_listing' => false
270
+ ));
271
+
272
+ /* ------ ship_width -------- */
273
+ $this->addAttribute('catalog_product', 'ship_width', array(
274
+ 'type' => 'decimal',
275
+ 'input' => 'text',
276
+ 'label' => 'Dimension Width',
277
+ 'global' => false,
278
+ 'visible' => 1,
279
+ 'required' => 0,
280
+ 'visible_on_front' => 0,
281
+ 'is_html_allowed_on_front' => 0,
282
+ 'searchable' => 0,
283
+ 'filterable' => 0,
284
+ 'comparable' => 0,
285
+ 'unique' => false,
286
+ 'user_defined' => true,
287
+ 'is_user_defined' => true,
288
+ 'used_in_product_listing' => false
289
+ ));
290
+
291
+ /* ------ ship_height -------- */
292
+ $this->addAttribute('catalog_product', 'ship_height', array(
293
+ 'type' => 'decimal',
294
+ 'input' => 'text',
295
+ 'label' => 'Dimension Height',
296
+ 'global' => false,
297
+ 'visible' => 1,
298
+ 'required' => 0,
299
+ 'visible_on_front' => 0,
300
+ 'is_html_allowed_on_front' => 0,
301
+ 'searchable' => 0,
302
+ 'filterable' => 0,
303
+ 'comparable' => 0,
304
+ 'unique' => false,
305
+ 'user_defined' => true,
306
+ 'is_user_defined' => true,
307
+ 'used_in_product_listing' => false
308
+ ));
309
+
310
+ /* ------ shipperhq_poss_boxes -------- */
311
+ $this->addAttribute('catalog_product', 'shipperhq_poss_boxes', array(
312
+ 'type' => 'varchar',
313
+ 'backend' => 'eav/entity_attribute_backend_array',
314
+ 'input' => 'multiselect',
315
+ 'label' => 'Possible Packing Boxes',
316
+ 'global' => false,
317
+ 'visible' => 1,
318
+ 'required' => 0,
319
+ 'visible_on_front' => 0,
320
+ 'is_html_allowed_on_front' => 0,
321
+ 'searchable' => 0,
322
+ 'filterable' => 0,
323
+ 'comparable' => 0,
324
+ 'unique' => false,
325
+ 'user_defined' => true,
326
+ 'is_user_defined' => true,
327
+ 'used_in_product_listing' => false
328
+ ));
329
+
330
+ /* ------ ship_box_tolerance -------- */
331
+ $this->addAttribute('catalog_product', 'ship_box_tolerance', array(
332
+ 'type' => 'int',
333
+ 'input' => 'text',
334
+ 'label' => 'Box Tolerance',
335
+ 'global' => false,
336
+ 'visible' => 1,
337
+ 'required' => 0,
338
+ 'visible_on_front' => 0,
339
+ 'is_html_allowed_on_front' => 0,
340
+ 'searchable' => 0,
341
+ 'filterable' => 0,
342
+ 'comparable' => 0,
343
+ 'unique' => false,
344
+ 'user_defined' => true,
345
+ 'is_user_defined' => true,
346
+ 'used_in_product_listing' => false,
347
+ 'note' => 'Note: Ignore if unsure'
348
+ ));
349
+
350
+ /*
351
+ *
352
+ *
353
+ *
354
+ */
355
+
356
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
357
+
358
+ //$attributeSetArr = $installer->getConnection()->fetchAll("SELECT attribute_set_id FROM {$this->getTable('eav_attribute_set')} WHERE entity_type_id={$entityTypeId}");
359
+ $attributeSetArr = $installer->getAllAttributeSetIds($entityTypeId);
360
+
361
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
362
+ $dimAttributeCodes = array('ship_separately' => '2',
363
+ 'shipperhq_dim_group' => '1',
364
+ 'shipperhq_volume_weight' => '9',
365
+ 'ship_length' => '10',
366
+ 'ship_width' => '11',
367
+ 'ship_height' => '12',
368
+ 'shipperhq_poss_boxes' => '20',
369
+ 'ship_box_tolerance' => '22',
370
+ 'shipperhq_declared_value' => '25'
371
+ );
372
+
373
+ foreach ($attributeSetArr as $attributeSetId) {
374
+
375
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
376
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
377
+
378
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
379
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
380
+
381
+ foreach($stdAttributeCodes as $code => $sort) {
382
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
383
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
384
+ }
385
+
386
+ foreach($dimAttributeCodes as $code => $sort) {
387
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
388
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
389
+ }
390
+
391
+ };
392
+
393
+
394
+
395
+ $text = Mage::helper('wsalogger')->getNewVersion() > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : 'text';
396
+
397
+ $isCheckout = array(
398
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
399
+ 'comment' => 'Shipperhq Shipper',
400
+ 'nullable' => 'false',
401
+ 'default' => '0'
402
+ );
403
+
404
+ $carrierType = array(
405
+ 'type' => $text,
406
+ 'comment' => 'Shipperhq Carrier Type',
407
+ 'nullable' => 'true',
408
+ );
409
+
410
+ $dispatchDate = array(
411
+ 'type' => $text,
412
+ 'length' => 20,
413
+ 'comment' => 'Dispatch Date',
414
+ 'nullable' => 'true');
415
+
416
+ $deliveryDate = array(
417
+ 'type' => $text,
418
+ 'length' => 20,
419
+ 'comment' => 'Expected Delivery',
420
+ 'nullable' => 'true');
421
+
422
+ $carrierNotice = array(
423
+ 'type' => $text,
424
+ 'comment' => 'Shipperhq Carrier Notice',
425
+ 'nullable' => 'true',
426
+ );
427
+
428
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
429
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
430
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
431
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
432
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
433
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
434
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
435
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
436
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
437
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
438
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
439
+
440
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/storage'))) {
441
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/storage'));
442
+
443
+ $table
444
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
445
+ 'primary' => true,
446
+ 'nullable' => false,
447
+ 'unsigned' => true
448
+ ))
449
+ ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '512k', array('nullable' => false))
450
+ ->addForeignKey(
451
+ $this->getFkName('shipperhq_shipper/storage', 'quote_id', 'sales/quote', 'entity_id'),
452
+ 'quote_id',
453
+ $this->getTable('sales/quote'),
454
+ 'entity_id',
455
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
456
+ )
457
+ ;
458
+ $this->getConnection()->createTable($table);
459
+ }
460
+
461
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.17.php ADDED
@@ -0,0 +1,444 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/attributeupdate'))) {
8
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/attributeupdate'));
9
+
10
+ $table
11
+ ->addColumn('synch_id', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array(
12
+ 'primary' => true,
13
+ 'nullable' => false,
14
+ 'unsigned' => true,
15
+ 'auto_increment' => true
16
+ ))
17
+ ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 0, array(
18
+ 'nullable' => false,
19
+ 'unsigned' => true,
20
+ ))
21
+ ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
22
+ 'nullable' => false,
23
+ ))
24
+ ->addColumn('attribute_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
25
+ 'nullable' => false,
26
+ ))
27
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
28
+ 'nullable' => false,
29
+ ))
30
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
31
+ 'nullable' => false,
32
+ ))
33
+ ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
34
+ 'nullable' => false,
35
+ ))
36
+ ;
37
+ $this->getConnection()->createTable($table);
38
+ }
39
+
40
+ /* ------ shipperhq_shipping_group -------- */
41
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_group', array(
42
+ 'type' => 'varchar',
43
+ 'backend' => 'eav/entity_attribute_backend_array',
44
+ 'input' => 'multiselect',
45
+ 'label' => 'Shipping Group',
46
+ 'global' => false,
47
+ 'visible' => 1,
48
+ 'required' => 0,
49
+ 'visible_on_front' => 0,
50
+ 'is_html_allowed_on_front' => 0,
51
+ 'searchable' => 0,
52
+ 'filterable' => 0,
53
+ 'comparable' => 0,
54
+ 'unique' => false,
55
+ 'user_defined' => true,
56
+ 'used_in_product_listing' => false
57
+ ));
58
+
59
+ /* ------ shipperhq_warehouse -------- */
60
+ $this->addAttribute('catalog_product', 'shipperhq_warehouse', array(
61
+ 'type' => 'text',
62
+ 'backend' => 'eav/entity_attribute_backend_array',
63
+ 'input' => 'multiselect',
64
+ 'label' => 'Origin',
65
+ 'global' => false,
66
+ 'visible' => 1,
67
+ 'required' => 0,
68
+ 'visible_on_front' => 0,
69
+ 'is_html_allowed_on_front' => 0,
70
+ 'searchable' => 0,
71
+ 'filterable' => 0,
72
+ 'comparable' => 0,
73
+ 'unique' => false,
74
+ 'user_defined' => true,
75
+ 'used_in_product_listing' => false
76
+ ));
77
+
78
+ /* ------ shipperhq_shipping_qty -------- */
79
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_qty', array(
80
+ 'type' => 'int',
81
+ 'input' => 'text',
82
+ 'label' => 'Shipping Qty',
83
+ 'global' => false,
84
+ 'visible' => 1,
85
+ 'required' => 0,
86
+ 'visible_on_front' => 0,
87
+ 'is_html_allowed_on_front' => 0,
88
+ 'searchable' => 0,
89
+ 'filterable' => 0,
90
+ 'comparable' => 0,
91
+ 'unique' => false,
92
+ 'user_defined' => true,
93
+ 'used_in_product_listing' => false
94
+ ));
95
+
96
+ /* ------ shipperhq_shipping_fee -------- */
97
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_fee', array(
98
+ 'type' => 'decimal',
99
+ 'input' => 'price',
100
+ 'label' => 'Shipping Fee',
101
+ 'global' => false,
102
+ 'visible' => 1,
103
+ 'required' => 0,
104
+ 'visible_on_front' => 0,
105
+ 'is_html_allowed_on_front' => 0,
106
+ 'searchable' => 0,
107
+ 'filterable' => 0,
108
+ 'comparable' => 0,
109
+ 'unique' => false,
110
+ 'user_defined' => true,
111
+ 'used_in_product_listing' => false
112
+ ));
113
+
114
+ /* ------ shipperhq_additional_price -------- */
115
+ $this->addAttribute('catalog_product', 'shipperhq_additional_price', array(
116
+ 'type' => 'decimal',
117
+ 'input' => 'price',
118
+ 'label' => 'Additional Price',
119
+ 'global' => false,
120
+ 'visible' => 1,
121
+ 'required' => 0,
122
+ 'visible_on_front' => 0,
123
+ 'is_html_allowed_on_front' => 0,
124
+ 'searchable' => 0,
125
+ 'filterable' => 0,
126
+ 'comparable' => 0,
127
+ 'unique' => false,
128
+ 'user_defined' => true,
129
+ 'used_in_product_listing' => false
130
+ ));
131
+
132
+ /* ------ shipperhq_handling_fee -------- */
133
+ $this->addAttribute('catalog_product', 'shipperhq_handling_fee', array(
134
+ 'type' => 'decimal',
135
+ 'input' => 'price',
136
+ 'label' => 'Handling Fee',
137
+ 'global' => false,
138
+ 'visible' => 1,
139
+ 'required' => 0,
140
+ 'visible_on_front' => 0,
141
+ 'is_html_allowed_on_front' => 0,
142
+ 'searchable' => 0,
143
+ 'filterable' => 0,
144
+ 'comparable' => 0,
145
+ 'unique' => false,
146
+ 'user_defined' => true,
147
+ 'used_in_product_listing' => false
148
+ ));
149
+
150
+ /* ------ shipperhq_carrier_code -------- */
151
+ $this->addAttribute('catalog_product', 'shipperhq_carrier_code', array(
152
+ 'type' => 'text',
153
+ 'input' => 'text',
154
+ 'label' => 'Carrier Code',
155
+ 'global' => false,
156
+ 'visible' => 1,
157
+ 'required' => 0,
158
+ 'visible_on_front' => 0,
159
+ 'is_html_allowed_on_front' => 0,
160
+ 'searchable' => 0,
161
+ 'filterable' => 0,
162
+ 'comparable' => 0,
163
+ 'unique' => false,
164
+ 'user_defined' => true,
165
+ 'used_in_product_listing' => false
166
+ ));
167
+
168
+ /* ------ shipperhq_volume_weight -------- */
169
+ $this->addAttribute('catalog_product', 'shipperhq_volume_weight', array(
170
+ 'type' => 'decimal',
171
+ 'input' => 'text',
172
+ 'label' => 'Volume Weight',
173
+ 'global' => false,
174
+ 'visible' => 1,
175
+ 'required' => 0,
176
+ 'visible_on_front' => 0,
177
+ 'is_html_allowed_on_front' => 0,
178
+ 'searchable' => 0,
179
+ 'filterable' => 0,
180
+ 'comparable' => 0,
181
+ 'unique' => false,
182
+ 'user_defined' => true,
183
+ 'used_in_product_listing' => false
184
+ ));
185
+
186
+ /* ------ shipperhq_declared_value -------- */
187
+ $this->addAttribute('catalog_product', 'shipperhq_declared_value', array(
188
+ 'type' => 'decimal',
189
+ 'input' => 'price',
190
+ 'label' => 'Declared Value',
191
+ 'global' => false,
192
+ 'visible' => 1,
193
+ 'required' => 0,
194
+ 'visible_on_front' => 0,
195
+ 'is_html_allowed_on_front' => 0,
196
+ 'searchable' => 0,
197
+ 'filterable' => 0,
198
+ 'comparable' => 0,
199
+ 'unique' => false,
200
+ 'user_defined' => true,
201
+ 'used_in_product_listing' => false,
202
+ 'note' => 'The deemed cost of this product for customs & insurance purposes'
203
+ ));
204
+
205
+ /* ------ ship_separately -------- */
206
+ $this->addAttribute('catalog_product', 'ship_separately', array(
207
+ 'type' => 'int',
208
+ 'input' => 'boolean',
209
+ 'label' => 'Ship Separately',
210
+ 'global' => false,
211
+ 'visible' => 1,
212
+ 'required' => 0,
213
+ 'visible_on_front' => 0,
214
+ 'is_html_allowed_on_front' => 0,
215
+ 'searchable' => 0,
216
+ 'filterable' => 0,
217
+ 'comparable' => 0,
218
+ 'unique' => false,
219
+ 'user_defined' => true,
220
+ 'used_in_product_listing' => false
221
+ ));
222
+
223
+ /* ------ shipperhq_dim_group -------- */
224
+ $this->addAttribute('catalog_product', 'shipperhq_dim_group', array(
225
+ 'type' => 'varchar',
226
+ 'input' => 'select',
227
+ 'label' => 'ShipperHQ Dimensional Rule Group',
228
+ 'backend' => 'eav/entity_attribute_backend_array',
229
+ 'global' => false,
230
+ 'visible' => 1,
231
+ 'required' => 0,
232
+ 'visible_on_front' => 0,
233
+ 'is_html_allowed_on_front' => 0,
234
+ 'searchable' => 0,
235
+ 'filterable' => 0,
236
+ 'comparable' => 0,
237
+ 'unique' => false,
238
+ 'user_defined' => true,
239
+ 'used_in_product_listing' => false
240
+ ));
241
+
242
+ /* ------ ship_length -------- */
243
+ $this->addAttribute('catalog_product', 'ship_length', array(
244
+ 'type' => 'decimal',
245
+ 'input' => 'text',
246
+ 'label' => 'Dimension Length',
247
+ 'global' => false,
248
+ 'visible' => 1,
249
+ 'required' => 0,
250
+ 'visible_on_front' => 0,
251
+ 'is_html_allowed_on_front' => 0,
252
+ 'searchable' => 0,
253
+ 'filterable' => 0,
254
+ 'comparable' => 0,
255
+ 'unique' => false,
256
+ 'user_defined' => true,
257
+ 'used_in_product_listing' => false
258
+ ));
259
+
260
+ /* ------ ship_width -------- */
261
+ $this->addAttribute('catalog_product', 'ship_width', array(
262
+ 'type' => 'decimal',
263
+ 'input' => 'text',
264
+ 'label' => 'Dimension Width',
265
+ 'global' => false,
266
+ 'visible' => 1,
267
+ 'required' => 0,
268
+ 'visible_on_front' => 0,
269
+ 'is_html_allowed_on_front' => 0,
270
+ 'searchable' => 0,
271
+ 'filterable' => 0,
272
+ 'comparable' => 0,
273
+ 'unique' => false,
274
+ 'user_defined' => true,
275
+ 'used_in_product_listing' => false
276
+ ));
277
+
278
+ /* ------ ship_height -------- */
279
+ $this->addAttribute('catalog_product', 'ship_height', array(
280
+ 'type' => 'decimal',
281
+ 'input' => 'text',
282
+ 'label' => 'Dimension Height',
283
+ 'global' => false,
284
+ 'visible' => 1,
285
+ 'required' => 0,
286
+ 'visible_on_front' => 0,
287
+ 'is_html_allowed_on_front' => 0,
288
+ 'searchable' => 0,
289
+ 'filterable' => 0,
290
+ 'comparable' => 0,
291
+ 'unique' => false,
292
+ 'user_defined' => true,
293
+ 'used_in_product_listing' => false
294
+ ));
295
+
296
+ /* ------ shipperhq_poss_boxes -------- */
297
+ $this->addAttribute('catalog_product', 'shipperhq_poss_boxes', array(
298
+ 'type' => 'varchar',
299
+ 'backend' => 'eav/entity_attribute_backend_array',
300
+ 'input' => 'multiselect',
301
+ 'label' => 'Possible Packing Boxes',
302
+ 'global' => false,
303
+ 'visible' => 1,
304
+ 'required' => 0,
305
+ 'visible_on_front' => 0,
306
+ 'is_html_allowed_on_front' => 0,
307
+ 'searchable' => 0,
308
+ 'filterable' => 0,
309
+ 'comparable' => 0,
310
+ 'unique' => false,
311
+ 'user_defined' => true,
312
+ 'used_in_product_listing' => false
313
+ ));
314
+
315
+ /* ------ ship_box_tolerance -------- */
316
+ $this->addAttribute('catalog_product', 'ship_box_tolerance', array(
317
+ 'type' => 'int',
318
+ 'input' => 'text',
319
+ 'label' => 'Box Tolerance',
320
+ 'global' => false,
321
+ 'visible' => 1,
322
+ 'required' => 0,
323
+ 'visible_on_front' => 0,
324
+ 'is_html_allowed_on_front' => 0,
325
+ 'searchable' => 0,
326
+ 'filterable' => 0,
327
+ 'comparable' => 0,
328
+ 'unique' => false,
329
+ 'used_in_product_listing' => false,
330
+ 'user_defined' => true,
331
+ 'note' => 'Note: Ignore if unsure'
332
+ ));
333
+
334
+ /*
335
+ *
336
+ *
337
+ *
338
+ */
339
+
340
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
341
+
342
+ $attributeSetArr = $installer->getAllAttributeSetIds($entityTypeId);
343
+
344
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
345
+ $dimAttributeCodes = array('ship_separately' => '2',
346
+ 'shipperhq_dim_group' => '1',
347
+ 'shipperhq_volume_weight' => '9',
348
+ 'ship_length' => '10',
349
+ 'ship_width' => '11',
350
+ 'ship_height' => '12',
351
+ 'shipperhq_poss_boxes' => '20',
352
+ 'ship_box_tolerance' => '22',
353
+ 'shipperhq_declared_value' => '25'
354
+ );
355
+
356
+ foreach ($attributeSetArr as $attributeSetId) {
357
+
358
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
359
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
360
+
361
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
362
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
363
+
364
+ foreach($stdAttributeCodes as $code => $sort) {
365
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
366
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
367
+ }
368
+
369
+ foreach($dimAttributeCodes as $code => $sort) {
370
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
371
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
372
+ }
373
+
374
+ };
375
+
376
+
377
+
378
+ $text = Mage::helper('wsalogger')->getNewVersion() > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : 'text';
379
+
380
+ $isCheckout = array(
381
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
382
+ 'comment' => 'Shipperhq Shipper',
383
+ 'nullable' => 'false',
384
+ 'default' => '0'
385
+ );
386
+
387
+ $carrierType = array(
388
+ 'type' => $text,
389
+ 'comment' => 'Shipperhq Carrier Type',
390
+ 'nullable' => 'true',
391
+ );
392
+
393
+ $dispatchDate = array(
394
+ 'type' => $text,
395
+ 'length' => 20,
396
+ 'comment' => 'Dispatch Date',
397
+ 'nullable' => 'true');
398
+
399
+ $deliveryDate = array(
400
+ 'type' => $text,
401
+ 'length' => 20,
402
+ 'comment' => 'Expected Delivery',
403
+ 'nullable' => 'true');
404
+
405
+ $carrierNotice = array(
406
+ 'type' => $text,
407
+ 'comment' => 'Shipperhq Carrier Notice',
408
+ 'nullable' => 'true',
409
+ );
410
+
411
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
412
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
413
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
414
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
415
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
416
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
417
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
418
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
419
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
420
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
421
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
422
+
423
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/storage'))) {
424
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/storage'));
425
+
426
+ $table
427
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
428
+ 'primary' => true,
429
+ 'nullable' => false,
430
+ 'unsigned' => true
431
+ ))
432
+ ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '512k', array('nullable' => false))
433
+ ->addForeignKey(
434
+ $this->getFkName('shipperhq_shipper/storage', 'quote_id', 'sales/quote', 'entity_id'),
435
+ 'quote_id',
436
+ $this->getTable('sales/quote'),
437
+ 'entity_id',
438
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
439
+ )
440
+ ;
441
+ $this->getConnection()->createTable($table);
442
+ }
443
+
444
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.18.php ADDED
@@ -0,0 +1,624 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/attributeupdate'))) {
8
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/attributeupdate'));
9
+
10
+ $table
11
+ ->addColumn('synch_id', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array(
12
+ 'primary' => true,
13
+ 'nullable' => false,
14
+ 'unsigned' => true,
15
+ 'auto_increment' => true
16
+ ))
17
+ ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 0, array(
18
+ 'nullable' => false,
19
+ 'unsigned' => true,
20
+ ))
21
+ ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
22
+ 'nullable' => false,
23
+ ))
24
+ ->addColumn('attribute_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
25
+ 'nullable' => false,
26
+ ))
27
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
28
+ 'nullable' => false,
29
+ ))
30
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
31
+ 'nullable' => false,
32
+ ))
33
+ ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
34
+ 'nullable' => false,
35
+ ))
36
+ ;
37
+ $this->getConnection()->createTable($table);
38
+ }
39
+
40
+ /* ------ shipperhq_shipping_group -------- */
41
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_group', array(
42
+ 'type' => 'varchar',
43
+ 'backend' => 'eav/entity_attribute_backend_array',
44
+ 'input' => 'multiselect',
45
+ 'label' => 'Shipping Group',
46
+ 'global' => false,
47
+ 'visible' => 1,
48
+ 'required' => 0,
49
+ 'visible_on_front' => 0,
50
+ 'is_html_allowed_on_front' => 0,
51
+ 'searchable' => 0,
52
+ 'filterable' => 0,
53
+ 'comparable' => 0,
54
+ 'unique' => false,
55
+ 'user_defined' => true,
56
+ 'used_in_product_listing' => false
57
+ ));
58
+
59
+ /* ------ shipperhq_warehouse -------- */
60
+ $this->addAttribute('catalog_product', 'shipperhq_warehouse', array(
61
+ 'type' => 'text',
62
+ 'backend' => 'eav/entity_attribute_backend_array',
63
+ 'input' => 'multiselect',
64
+ 'label' => 'Origin',
65
+ 'global' => false,
66
+ 'visible' => 1,
67
+ 'required' => 0,
68
+ 'visible_on_front' => 0,
69
+ 'is_html_allowed_on_front' => 0,
70
+ 'searchable' => 0,
71
+ 'filterable' => 0,
72
+ 'comparable' => 0,
73
+ 'unique' => false,
74
+ 'user_defined' => true,
75
+ 'used_in_product_listing' => false
76
+ ));
77
+
78
+ /* ------ shipperhq_shipping_qty -------- */
79
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_qty', array(
80
+ 'type' => 'int',
81
+ 'input' => 'text',
82
+ 'label' => 'Shipping Qty',
83
+ 'global' => false,
84
+ 'visible' => 1,
85
+ 'required' => 0,
86
+ 'visible_on_front' => 0,
87
+ 'is_html_allowed_on_front' => 0,
88
+ 'searchable' => 0,
89
+ 'filterable' => 0,
90
+ 'comparable' => 0,
91
+ 'unique' => false,
92
+ 'user_defined' => true,
93
+ 'used_in_product_listing' => false
94
+ ));
95
+
96
+ /* ------ shipperhq_shipping_fee -------- */
97
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_fee', array(
98
+ 'type' => 'decimal',
99
+ 'input' => 'price',
100
+ 'label' => 'Shipping Fee',
101
+ 'global' => false,
102
+ 'visible' => 1,
103
+ 'required' => 0,
104
+ 'visible_on_front' => 0,
105
+ 'is_html_allowed_on_front' => 0,
106
+ 'searchable' => 0,
107
+ 'filterable' => 0,
108
+ 'comparable' => 0,
109
+ 'unique' => false,
110
+ 'user_defined' => true,
111
+ 'used_in_product_listing' => false
112
+ ));
113
+
114
+ /* ------ shipperhq_additional_price -------- */
115
+ $this->addAttribute('catalog_product', 'shipperhq_additional_price', array(
116
+ 'type' => 'decimal',
117
+ 'input' => 'price',
118
+ 'label' => 'Additional Price',
119
+ 'global' => false,
120
+ 'visible' => 1,
121
+ 'required' => 0,
122
+ 'visible_on_front' => 0,
123
+ 'is_html_allowed_on_front' => 0,
124
+ 'searchable' => 0,
125
+ 'filterable' => 0,
126
+ 'comparable' => 0,
127
+ 'unique' => false,
128
+ 'user_defined' => true,
129
+ 'used_in_product_listing' => false
130
+ ));
131
+
132
+ /* ------ shipperhq_handling_fee -------- */
133
+ $this->addAttribute('catalog_product', 'shipperhq_handling_fee', array(
134
+ 'type' => 'decimal',
135
+ 'input' => 'price',
136
+ 'label' => 'Handling Fee',
137
+ 'global' => false,
138
+ 'visible' => 1,
139
+ 'required' => 0,
140
+ 'visible_on_front' => 0,
141
+ 'is_html_allowed_on_front' => 0,
142
+ 'searchable' => 0,
143
+ 'filterable' => 0,
144
+ 'comparable' => 0,
145
+ 'unique' => false,
146
+ 'user_defined' => true,
147
+ 'used_in_product_listing' => false
148
+ ));
149
+
150
+ /* ------ shipperhq_carrier_code -------- */
151
+ $this->addAttribute('catalog_product', 'shipperhq_carrier_code', array(
152
+ 'type' => 'text',
153
+ 'input' => 'text',
154
+ 'label' => 'Carrier Code',
155
+ 'global' => false,
156
+ 'visible' => 1,
157
+ 'required' => 0,
158
+ 'visible_on_front' => 0,
159
+ 'is_html_allowed_on_front' => 0,
160
+ 'searchable' => 0,
161
+ 'filterable' => 0,
162
+ 'comparable' => 0,
163
+ 'unique' => false,
164
+ 'user_defined' => true,
165
+ 'used_in_product_listing' => false
166
+ ));
167
+
168
+ /* ------ shipperhq_volume_weight -------- */
169
+ $this->addAttribute('catalog_product', 'shipperhq_volume_weight', array(
170
+ 'type' => 'decimal',
171
+ 'input' => 'text',
172
+ 'label' => 'Volume Weight',
173
+ 'global' => false,
174
+ 'visible' => 1,
175
+ 'required' => 0,
176
+ 'visible_on_front' => 0,
177
+ 'is_html_allowed_on_front' => 0,
178
+ 'searchable' => 0,
179
+ 'filterable' => 0,
180
+ 'comparable' => 0,
181
+ 'unique' => false,
182
+ 'user_defined' => true,
183
+ 'used_in_product_listing' => false
184
+ ));
185
+
186
+ /* ------ shipperhq_declared_value -------- */
187
+ $this->addAttribute('catalog_product', 'shipperhq_declared_value', array(
188
+ 'type' => 'decimal',
189
+ 'input' => 'price',
190
+ 'label' => 'Declared Value',
191
+ 'global' => false,
192
+ 'visible' => 1,
193
+ 'required' => 0,
194
+ 'visible_on_front' => 0,
195
+ 'is_html_allowed_on_front' => 0,
196
+ 'searchable' => 0,
197
+ 'filterable' => 0,
198
+ 'comparable' => 0,
199
+ 'unique' => false,
200
+ 'user_defined' => true,
201
+ 'used_in_product_listing' => false,
202
+ 'note' => 'The deemed cost of this product for customs & insurance purposes'
203
+ ));
204
+
205
+ /* ------ ship_separately -------- */
206
+ $this->addAttribute('catalog_product', 'ship_separately', array(
207
+ 'type' => 'int',
208
+ 'input' => 'boolean',
209
+ 'label' => 'Ship Separately',
210
+ 'global' => false,
211
+ 'visible' => 1,
212
+ 'required' => 0,
213
+ 'visible_on_front' => 0,
214
+ 'is_html_allowed_on_front' => 0,
215
+ 'searchable' => 0,
216
+ 'filterable' => 0,
217
+ 'comparable' => 0,
218
+ 'unique' => false,
219
+ 'user_defined' => true,
220
+ 'used_in_product_listing' => false
221
+ ));
222
+
223
+ /* ------ shipperhq_dim_group -------- */
224
+ $this->addAttribute('catalog_product', 'shipperhq_dim_group', array(
225
+ 'type' => 'varchar',
226
+ 'input' => 'select',
227
+ 'label' => 'ShipperHQ Dimensional Rule Group',
228
+ 'backend' => 'eav/entity_attribute_backend_array',
229
+ 'global' => false,
230
+ 'visible' => 1,
231
+ 'required' => 0,
232
+ 'visible_on_front' => 0,
233
+ 'is_html_allowed_on_front' => 0,
234
+ 'searchable' => 0,
235
+ 'filterable' => 0,
236
+ 'comparable' => 0,
237
+ 'unique' => false,
238
+ 'user_defined' => true,
239
+ 'used_in_product_listing' => false
240
+ ));
241
+
242
+ /* ------ ship_length -------- */
243
+ $this->addAttribute('catalog_product', 'ship_length', array(
244
+ 'type' => 'decimal',
245
+ 'input' => 'text',
246
+ 'label' => 'Dimension Length',
247
+ 'global' => false,
248
+ 'visible' => 1,
249
+ 'required' => 0,
250
+ 'visible_on_front' => 0,
251
+ 'is_html_allowed_on_front' => 0,
252
+ 'searchable' => 0,
253
+ 'filterable' => 0,
254
+ 'comparable' => 0,
255
+ 'unique' => false,
256
+ 'user_defined' => true,
257
+ 'used_in_product_listing' => false
258
+ ));
259
+
260
+ /* ------ ship_width -------- */
261
+ $this->addAttribute('catalog_product', 'ship_width', array(
262
+ 'type' => 'decimal',
263
+ 'input' => 'text',
264
+ 'label' => 'Dimension Width',
265
+ 'global' => false,
266
+ 'visible' => 1,
267
+ 'required' => 0,
268
+ 'visible_on_front' => 0,
269
+ 'is_html_allowed_on_front' => 0,
270
+ 'searchable' => 0,
271
+ 'filterable' => 0,
272
+ 'comparable' => 0,
273
+ 'unique' => false,
274
+ 'user_defined' => true,
275
+ 'used_in_product_listing' => false
276
+ ));
277
+
278
+ /* ------ ship_height -------- */
279
+ $this->addAttribute('catalog_product', 'ship_height', array(
280
+ 'type' => 'decimal',
281
+ 'input' => 'text',
282
+ 'label' => 'Dimension Height',
283
+ 'global' => false,
284
+ 'visible' => 1,
285
+ 'required' => 0,
286
+ 'visible_on_front' => 0,
287
+ 'is_html_allowed_on_front' => 0,
288
+ 'searchable' => 0,
289
+ 'filterable' => 0,
290
+ 'comparable' => 0,
291
+ 'unique' => false,
292
+ 'user_defined' => true,
293
+ 'used_in_product_listing' => false
294
+ ));
295
+
296
+ /* ------ shipperhq_poss_boxes -------- */
297
+ $this->addAttribute('catalog_product', 'shipperhq_poss_boxes', array(
298
+ 'type' => 'varchar',
299
+ 'backend' => 'eav/entity_attribute_backend_array',
300
+ 'input' => 'multiselect',
301
+ 'label' => 'Possible Packing Boxes',
302
+ 'global' => false,
303
+ 'visible' => 1,
304
+ 'required' => 0,
305
+ 'visible_on_front' => 0,
306
+ 'is_html_allowed_on_front' => 0,
307
+ 'searchable' => 0,
308
+ 'filterable' => 0,
309
+ 'comparable' => 0,
310
+ 'unique' => false,
311
+ 'user_defined' => true,
312
+ 'used_in_product_listing' => false
313
+ ));
314
+
315
+ /* ------ ship_box_tolerance -------- */
316
+ $this->addAttribute('catalog_product', 'ship_box_tolerance', array(
317
+ 'type' => 'int',
318
+ 'input' => 'text',
319
+ 'label' => 'Box Tolerance',
320
+ 'global' => false,
321
+ 'visible' => 1,
322
+ 'required' => 0,
323
+ 'visible_on_front' => 0,
324
+ 'is_html_allowed_on_front' => 0,
325
+ 'searchable' => 0,
326
+ 'filterable' => 0,
327
+ 'comparable' => 0,
328
+ 'unique' => false,
329
+ 'used_in_product_listing' => false,
330
+ 'user_defined' => true,
331
+ 'note' => 'Note: Ignore if unsure'
332
+ ));
333
+
334
+ /*
335
+ *
336
+ *
337
+ *
338
+ */
339
+
340
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
341
+
342
+ $attributeSetArr = $installer->getAllAttributeSetIds($entityTypeId);
343
+
344
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
345
+ $dimAttributeCodes = array('ship_separately' => '2',
346
+ 'shipperhq_dim_group' => '1',
347
+ 'shipperhq_volume_weight' => '9',
348
+ 'ship_length' => '10',
349
+ 'ship_width' => '11',
350
+ 'ship_height' => '12',
351
+ 'shipperhq_poss_boxes' => '20',
352
+ );
353
+
354
+ foreach ($attributeSetArr as $attributeSetId) {
355
+
356
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
357
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
358
+
359
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
360
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
361
+
362
+ foreach($stdAttributeCodes as $code => $sort) {
363
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
364
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
365
+ }
366
+
367
+ foreach($dimAttributeCodes as $code => $sort) {
368
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
369
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
370
+ }
371
+
372
+ };
373
+
374
+
375
+
376
+ $text = Mage::helper('wsalogger')->getNewVersion() > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : 'text';
377
+
378
+ $isCheckout = array(
379
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
380
+ 'comment' => 'Shipperhq Shipper',
381
+ 'nullable' => 'false',
382
+ 'default' => '0'
383
+ );
384
+
385
+ $carrierType = array(
386
+ 'type' => $text,
387
+ 'comment' => 'Shipperhq Carrier Type',
388
+ 'nullable' => 'true',
389
+ );
390
+
391
+ $dispatchDate = array(
392
+ 'type' => $text,
393
+ 'length' => 20,
394
+ 'comment' => 'Dispatch Date',
395
+ 'nullable' => 'true');
396
+
397
+ $deliveryDate = array(
398
+ 'type' => $text,
399
+ 'length' => 20,
400
+ 'comment' => 'Expected Delivery',
401
+ 'nullable' => 'true');
402
+
403
+ $carrierNotice = array(
404
+ 'type' => $text,
405
+ 'comment' => 'Shipperhq Carrier Notice',
406
+ 'nullable' => 'true',
407
+ );
408
+
409
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'is_checkout')){
410
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
411
+ }
412
+
413
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carrier_type')){
414
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
415
+ }
416
+
417
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'dispatch_date')){
418
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
419
+ }
420
+
421
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'delivery_date')){
422
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
423
+ }
424
+
425
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type')){
426
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
427
+ }
428
+
429
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'dispatch_date')){
430
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
431
+ }
432
+
433
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'delivery_date')){
434
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
435
+ }
436
+
437
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice')){
438
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
439
+ }
440
+
441
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carrier_type')){
442
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
443
+ }
444
+
445
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'dispatch_date')){
446
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
447
+ }
448
+
449
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'delivery_date')){
450
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
451
+ }
452
+
453
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/storage'))) {
454
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/storage'));
455
+
456
+ $table
457
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
458
+ 'primary' => true,
459
+ 'nullable' => false,
460
+ 'unsigned' => true
461
+ ))
462
+ ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '512k', array('nullable' => false))
463
+ ->addForeignKey(
464
+ $this->getFkName('shipperhq_shipper/storage', 'quote_id', 'sales/quote', 'entity_id'),
465
+ 'quote_id',
466
+ $this->getTable('sales/quote'),
467
+ 'entity_id',
468
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
469
+ )
470
+ ;
471
+ $this->getConnection()->createTable($table);
472
+ }
473
+
474
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_packages'))) {
475
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_packages'));
476
+
477
+ $table
478
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
479
+ 'primary' => true,
480
+ 'nullable' => false,
481
+ 'unsigned' => true,
482
+ 'auto_increment' => true
483
+ ))
484
+ ->addColumn('address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
485
+ 'nullable' => false,
486
+ 'unsigned' => true
487
+ ))
488
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
489
+ 'nullable' => false,
490
+ ))
491
+ ->addColumn('carrier_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
492
+ 'nullable' => false,
493
+ ))
494
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
495
+ 'nullable' => true
496
+ ))
497
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
498
+ 'nullable' => true
499
+ ))
500
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
501
+ 'nullable' => true
502
+ ))
503
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
504
+ 'nullable' => true
505
+ ))
506
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
507
+ 'nullable' => true
508
+ ))
509
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
510
+ 'nullable' => true
511
+ ))
512
+ ->addForeignKey(
513
+ $this->getFkName('shipperhq_shipper/quote_packages', 'address_id', 'sales/quote_address', 'address_id'),
514
+ 'address_id',
515
+ $this->getTable('sales/quote_address'),
516
+ 'address_id',
517
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
518
+ )
519
+ ;
520
+ $this->getConnection()->createTable($table);
521
+ }
522
+
523
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_package_items'))) {
524
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_package_items'));
525
+
526
+ $table
527
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
528
+ 'nullable' => false,
529
+ ))
530
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
531
+ 'nullable' => false,
532
+ ))
533
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
534
+ 'nullable' => true
535
+ ))
536
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
537
+ 'nullable' => true
538
+ ))
539
+ ->addForeignKey(
540
+ $this->getFkName('shipperhq_shipper/quote_package_items', 'package_id', 'shipperhq_shipper/quote_packages', 'package_id'),
541
+ 'package_id',
542
+ $this->getTable('shipperhq_shipper/quote_packages'),
543
+ 'package_id',
544
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
545
+ )
546
+ ;
547
+ $this->getConnection()->createTable($table);
548
+ }
549
+
550
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_packages'))) {
551
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_packages'));
552
+
553
+ $table
554
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
555
+ 'primary' => true,
556
+ 'nullable' => false,
557
+ 'unsigned' => true,
558
+ 'auto_increment' => true
559
+ ))
560
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
561
+ 'nullable' => false,
562
+ 'unsigned' => true
563
+ ))
564
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
565
+ 'nullable' => false,
566
+ ))
567
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
568
+ 'nullable' => true
569
+ ))
570
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
571
+ 'nullable' => true
572
+ ))
573
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
574
+ 'nullable' => true
575
+ ))
576
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
577
+ 'nullable' => true
578
+ ))
579
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
580
+ 'nullable' => true
581
+ ))
582
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
583
+ 'nullable' => true
584
+ ))
585
+ ->addForeignKey(
586
+ $this->getFkName('shipperhq_shipper/order_packages', 'order_id', 'sales/order', 'entity_id'),
587
+ 'order_id',
588
+ $this->getTable('sales/order'),
589
+ 'entity_id',
590
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
591
+ )
592
+ ;
593
+ $this->getConnection()->createTable($table);
594
+ }
595
+
596
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_package_items'))) {
597
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_package_items'));
598
+
599
+ $table
600
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
601
+ 'nullable' => false,
602
+ 'unsigned' => true,
603
+ ))
604
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
605
+ 'nullable' => false,
606
+ ))
607
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
608
+ 'nullable' => true
609
+ ))
610
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
611
+ 'nullable' => true
612
+ ))
613
+ ->addForeignKey(
614
+ $this->getFkName('shipperhq_shipper/order_package_items', 'package_id', 'shipperhq_shipper/order_packages', 'package_id'),
615
+ 'package_id',
616
+ $this->getTable('shipperhq_shipper/order_packages'),
617
+ 'package_id',
618
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
619
+ )
620
+ ;
621
+ $this->getConnection()->createTable($table);
622
+ }
623
+
624
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.19.php ADDED
@@ -0,0 +1,629 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/attributeupdate'))) {
8
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/attributeupdate'));
9
+
10
+ $table
11
+ ->addColumn('synch_id', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array(
12
+ 'primary' => true,
13
+ 'nullable' => false,
14
+ 'unsigned' => true,
15
+ 'auto_increment' => true
16
+ ))
17
+ ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 0, array(
18
+ 'nullable' => false,
19
+ 'unsigned' => true,
20
+ ))
21
+ ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
22
+ 'nullable' => false,
23
+ ))
24
+ ->addColumn('attribute_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
25
+ 'nullable' => false,
26
+ ))
27
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
28
+ 'nullable' => false,
29
+ ))
30
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
31
+ 'nullable' => false,
32
+ ))
33
+ ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
34
+ 'nullable' => false,
35
+ ))
36
+ ;
37
+ $this->getConnection()->createTable($table);
38
+ }
39
+
40
+ /* ------ shipperhq_shipping_group -------- */
41
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_group', array(
42
+ 'type' => 'varchar',
43
+ 'backend' => 'eav/entity_attribute_backend_array',
44
+ 'input' => 'multiselect',
45
+ 'label' => 'Shipping Group',
46
+ 'global' => false,
47
+ 'visible' => 1,
48
+ 'required' => 0,
49
+ 'visible_on_front' => 0,
50
+ 'is_html_allowed_on_front' => 0,
51
+ 'searchable' => 0,
52
+ 'filterable' => 0,
53
+ 'comparable' => 0,
54
+ 'unique' => false,
55
+ 'user_defined' => true,
56
+ 'used_in_product_listing' => false
57
+ ));
58
+
59
+ /* ------ shipperhq_warehouse -------- */
60
+ $this->addAttribute('catalog_product', 'shipperhq_warehouse', array(
61
+ 'type' => 'text',
62
+ 'backend' => 'eav/entity_attribute_backend_array',
63
+ 'input' => 'multiselect',
64
+ 'label' => 'Origin',
65
+ 'global' => false,
66
+ 'visible' => 1,
67
+ 'required' => 0,
68
+ 'visible_on_front' => 0,
69
+ 'is_html_allowed_on_front' => 0,
70
+ 'searchable' => 0,
71
+ 'filterable' => 0,
72
+ 'comparable' => 0,
73
+ 'unique' => false,
74
+ 'user_defined' => true,
75
+ 'used_in_product_listing' => false
76
+ ));
77
+
78
+ /* ------ shipperhq_shipping_qty -------- */
79
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_qty', array(
80
+ 'type' => 'int',
81
+ 'input' => 'text',
82
+ 'label' => 'Shipping Qty',
83
+ 'global' => false,
84
+ 'visible' => 1,
85
+ 'required' => 0,
86
+ 'visible_on_front' => 0,
87
+ 'is_html_allowed_on_front' => 0,
88
+ 'searchable' => 0,
89
+ 'filterable' => 0,
90
+ 'comparable' => 0,
91
+ 'unique' => false,
92
+ 'user_defined' => true,
93
+ 'used_in_product_listing' => false
94
+ ));
95
+
96
+ /* ------ shipperhq_shipping_fee -------- */
97
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_fee', array(
98
+ 'type' => 'decimal',
99
+ 'input' => 'price',
100
+ 'label' => 'Shipping Fee',
101
+ 'global' => false,
102
+ 'visible' => 1,
103
+ 'required' => 0,
104
+ 'visible_on_front' => 0,
105
+ 'is_html_allowed_on_front' => 0,
106
+ 'searchable' => 0,
107
+ 'filterable' => 0,
108
+ 'comparable' => 0,
109
+ 'unique' => false,
110
+ 'user_defined' => true,
111
+ 'used_in_product_listing' => false
112
+ ));
113
+
114
+ /* ------ shipperhq_additional_price -------- */
115
+ $this->addAttribute('catalog_product', 'shipperhq_additional_price', array(
116
+ 'type' => 'decimal',
117
+ 'input' => 'price',
118
+ 'label' => 'Additional Price',
119
+ 'global' => false,
120
+ 'visible' => 1,
121
+ 'required' => 0,
122
+ 'visible_on_front' => 0,
123
+ 'is_html_allowed_on_front' => 0,
124
+ 'searchable' => 0,
125
+ 'filterable' => 0,
126
+ 'comparable' => 0,
127
+ 'unique' => false,
128
+ 'user_defined' => true,
129
+ 'used_in_product_listing' => false
130
+ ));
131
+
132
+ /* ------ shipperhq_handling_fee -------- */
133
+ $this->addAttribute('catalog_product', 'shipperhq_handling_fee', array(
134
+ 'type' => 'decimal',
135
+ 'input' => 'price',
136
+ 'label' => 'Handling Fee',
137
+ 'global' => false,
138
+ 'visible' => 1,
139
+ 'required' => 0,
140
+ 'visible_on_front' => 0,
141
+ 'is_html_allowed_on_front' => 0,
142
+ 'searchable' => 0,
143
+ 'filterable' => 0,
144
+ 'comparable' => 0,
145
+ 'unique' => false,
146
+ 'user_defined' => true,
147
+ 'used_in_product_listing' => false
148
+ ));
149
+
150
+ /* ------ shipperhq_carrier_code -------- */
151
+ $this->addAttribute('catalog_product', 'shipperhq_carrier_code', array(
152
+ 'type' => 'text',
153
+ 'input' => 'text',
154
+ 'label' => 'Carrier Code',
155
+ 'global' => false,
156
+ 'visible' => 1,
157
+ 'required' => 0,
158
+ 'visible_on_front' => 0,
159
+ 'is_html_allowed_on_front' => 0,
160
+ 'searchable' => 0,
161
+ 'filterable' => 0,
162
+ 'comparable' => 0,
163
+ 'unique' => false,
164
+ 'user_defined' => true,
165
+ 'used_in_product_listing' => false
166
+ ));
167
+
168
+ /* ------ shipperhq_volume_weight -------- */
169
+ $this->addAttribute('catalog_product', 'shipperhq_volume_weight', array(
170
+ 'type' => 'decimal',
171
+ 'input' => 'text',
172
+ 'label' => 'Volume Weight',
173
+ 'global' => false,
174
+ 'visible' => 1,
175
+ 'required' => 0,
176
+ 'visible_on_front' => 0,
177
+ 'is_html_allowed_on_front' => 0,
178
+ 'searchable' => 0,
179
+ 'filterable' => 0,
180
+ 'comparable' => 0,
181
+ 'unique' => false,
182
+ 'user_defined' => true,
183
+ 'used_in_product_listing' => false
184
+ ));
185
+
186
+ /* ------ shipperhq_declared_value -------- */
187
+ $this->addAttribute('catalog_product', 'shipperhq_declared_value', array(
188
+ 'type' => 'decimal',
189
+ 'input' => 'price',
190
+ 'label' => 'Declared Value',
191
+ 'global' => false,
192
+ 'visible' => 1,
193
+ 'required' => 0,
194
+ 'visible_on_front' => 0,
195
+ 'is_html_allowed_on_front' => 0,
196
+ 'searchable' => 0,
197
+ 'filterable' => 0,
198
+ 'comparable' => 0,
199
+ 'unique' => false,
200
+ 'user_defined' => true,
201
+ 'used_in_product_listing' => false,
202
+ 'note' => 'The deemed cost of this product for customs & insurance purposes'
203
+ ));
204
+
205
+ /* ------ ship_separately -------- */
206
+ $this->addAttribute('catalog_product', 'ship_separately', array(
207
+ 'type' => 'int',
208
+ 'input' => 'boolean',
209
+ 'label' => 'Ship Separately',
210
+ 'global' => false,
211
+ 'visible' => 1,
212
+ 'required' => 0,
213
+ 'visible_on_front' => 0,
214
+ 'is_html_allowed_on_front' => 0,
215
+ 'searchable' => 0,
216
+ 'filterable' => 0,
217
+ 'comparable' => 0,
218
+ 'unique' => false,
219
+ 'user_defined' => true,
220
+ 'used_in_product_listing' => false
221
+ ));
222
+
223
+ /* ------ shipperhq_dim_group -------- */
224
+ $this->addAttribute('catalog_product', 'shipperhq_dim_group', array(
225
+ 'type' => 'varchar',
226
+ 'input' => 'select',
227
+ 'label' => 'ShipperHQ Dimensional Rule Group',
228
+ 'backend' => 'eav/entity_attribute_backend_array',
229
+ 'global' => false,
230
+ 'visible' => 1,
231
+ 'required' => 0,
232
+ 'visible_on_front' => 0,
233
+ 'is_html_allowed_on_front' => 0,
234
+ 'searchable' => 0,
235
+ 'filterable' => 0,
236
+ 'comparable' => 0,
237
+ 'unique' => false,
238
+ 'user_defined' => true,
239
+ 'used_in_product_listing' => false
240
+ ));
241
+
242
+ /* ------ ship_length -------- */
243
+ $this->addAttribute('catalog_product', 'ship_length', array(
244
+ 'type' => 'decimal',
245
+ 'input' => 'text',
246
+ 'label' => 'Dimension Length',
247
+ 'global' => false,
248
+ 'visible' => 1,
249
+ 'required' => 0,
250
+ 'visible_on_front' => 0,
251
+ 'is_html_allowed_on_front' => 0,
252
+ 'searchable' => 0,
253
+ 'filterable' => 0,
254
+ 'comparable' => 0,
255
+ 'unique' => false,
256
+ 'user_defined' => true,
257
+ 'used_in_product_listing' => false
258
+ ));
259
+
260
+ /* ------ ship_width -------- */
261
+ $this->addAttribute('catalog_product', 'ship_width', array(
262
+ 'type' => 'decimal',
263
+ 'input' => 'text',
264
+ 'label' => 'Dimension Width',
265
+ 'global' => false,
266
+ 'visible' => 1,
267
+ 'required' => 0,
268
+ 'visible_on_front' => 0,
269
+ 'is_html_allowed_on_front' => 0,
270
+ 'searchable' => 0,
271
+ 'filterable' => 0,
272
+ 'comparable' => 0,
273
+ 'unique' => false,
274
+ 'user_defined' => true,
275
+ 'used_in_product_listing' => false
276
+ ));
277
+
278
+ /* ------ ship_height -------- */
279
+ $this->addAttribute('catalog_product', 'ship_height', array(
280
+ 'type' => 'decimal',
281
+ 'input' => 'text',
282
+ 'label' => 'Dimension Height',
283
+ 'global' => false,
284
+ 'visible' => 1,
285
+ 'required' => 0,
286
+ 'visible_on_front' => 0,
287
+ 'is_html_allowed_on_front' => 0,
288
+ 'searchable' => 0,
289
+ 'filterable' => 0,
290
+ 'comparable' => 0,
291
+ 'unique' => false,
292
+ 'user_defined' => true,
293
+ 'used_in_product_listing' => false
294
+ ));
295
+
296
+ /* ------ shipperhq_poss_boxes -------- */
297
+ $this->addAttribute('catalog_product', 'shipperhq_poss_boxes', array(
298
+ 'type' => 'varchar',
299
+ 'backend' => 'eav/entity_attribute_backend_array',
300
+ 'input' => 'multiselect',
301
+ 'label' => 'Possible Packing Boxes',
302
+ 'global' => false,
303
+ 'visible' => 1,
304
+ 'required' => 0,
305
+ 'visible_on_front' => 0,
306
+ 'is_html_allowed_on_front' => 0,
307
+ 'searchable' => 0,
308
+ 'filterable' => 0,
309
+ 'comparable' => 0,
310
+ 'unique' => false,
311
+ 'user_defined' => true,
312
+ 'used_in_product_listing' => false
313
+ ));
314
+
315
+ /* ------ ship_box_tolerance -------- */
316
+ $this->addAttribute('catalog_product', 'ship_box_tolerance', array(
317
+ 'type' => 'int',
318
+ 'input' => 'text',
319
+ 'label' => 'Box Tolerance',
320
+ 'global' => false,
321
+ 'visible' => 1,
322
+ 'required' => 0,
323
+ 'visible_on_front' => 0,
324
+ 'is_html_allowed_on_front' => 0,
325
+ 'searchable' => 0,
326
+ 'filterable' => 0,
327
+ 'comparable' => 0,
328
+ 'unique' => false,
329
+ 'used_in_product_listing' => false,
330
+ 'user_defined' => true,
331
+ 'note' => 'Note: Ignore if unsure'
332
+ ));
333
+
334
+ /*
335
+ *
336
+ *
337
+ *
338
+ */
339
+
340
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
341
+
342
+ $attributeSetArr = $installer->getAllAttributeSetIds($entityTypeId);
343
+
344
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
345
+ $dimAttributeCodes = array('ship_separately' => '2',
346
+ 'shipperhq_dim_group' => '1',
347
+ 'ship_length' => '10',
348
+ 'ship_width' => '11',
349
+ 'ship_height' => '12',
350
+ 'shipperhq_poss_boxes' => '20',
351
+ );
352
+
353
+ foreach ($attributeSetArr as $attributeSetId) {
354
+
355
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
356
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
357
+
358
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
359
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
360
+
361
+ foreach($stdAttributeCodes as $code => $sort) {
362
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
363
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
364
+ }
365
+
366
+ foreach($dimAttributeCodes as $code => $sort) {
367
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
368
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
369
+ }
370
+
371
+ };
372
+
373
+
374
+
375
+ $text = Mage::helper('wsalogger')->getNewVersion() > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : 'text';
376
+
377
+ $isCheckout = array(
378
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
379
+ 'comment' => 'Shipperhq Shipper',
380
+ 'nullable' => 'false',
381
+ 'default' => '0'
382
+ );
383
+
384
+ $carrierType = array(
385
+ 'type' => $text,
386
+ 'comment' => 'Shipperhq Carrier Type',
387
+ 'nullable' => 'true',
388
+ );
389
+
390
+ $dispatchDate = array(
391
+ 'type' => $text,
392
+ 'length' => 20,
393
+ 'comment' => 'Dispatch Date',
394
+ 'nullable' => 'true');
395
+
396
+ $deliveryDate = array(
397
+ 'type' => $text,
398
+ 'length' => 20,
399
+ 'comment' => 'Expected Delivery',
400
+ 'nullable' => 'true');
401
+
402
+ $carrierNotice = array(
403
+ 'type' => $text,
404
+ 'comment' => 'Shipperhq Carrier Notice',
405
+ 'nullable' => 'true',
406
+ );
407
+
408
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'is_checkout')){
409
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
410
+ }
411
+
412
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carrier_type')){
413
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
414
+ }
415
+
416
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'dispatch_date')){
417
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
418
+ }
419
+
420
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'delivery_date')){
421
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
422
+ }
423
+
424
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type')){
425
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
426
+ }
427
+
428
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'dispatch_date')){
429
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
430
+ }
431
+
432
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'delivery_date')){
433
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
434
+ }
435
+
436
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice')){
437
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
438
+ }
439
+
440
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carrier_type')){
441
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
442
+ }
443
+
444
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'dispatch_date')){
445
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
446
+ }
447
+
448
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'delivery_date')){
449
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
450
+ }
451
+
452
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/storage'))) {
453
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/storage'));
454
+
455
+ $table
456
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
457
+ 'primary' => true,
458
+ 'nullable' => false,
459
+ 'unsigned' => true
460
+ ))
461
+ ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '512k', array('nullable' => false))
462
+ ->addForeignKey(
463
+ $this->getFkName('shipperhq_shipper/storage', 'quote_id', 'sales/quote', 'entity_id'),
464
+ 'quote_id',
465
+ $this->getTable('sales/quote'),
466
+ 'entity_id',
467
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
468
+ )
469
+ ;
470
+ $this->getConnection()->createTable($table);
471
+ }
472
+
473
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_packages'))) {
474
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_packages'));
475
+
476
+ $table
477
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
478
+ 'primary' => true,
479
+ 'nullable' => false,
480
+ 'unsigned' => true,
481
+ 'auto_increment' => true
482
+ ))
483
+ ->addColumn('address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
484
+ 'nullable' => false,
485
+ 'unsigned' => true
486
+ ))
487
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
488
+ 'nullable' => false,
489
+ ))
490
+ ->addColumn('carrier_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
491
+ 'nullable' => false,
492
+ ))
493
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
494
+ 'nullable' => false,
495
+ ))
496
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
497
+ 'nullable' => true
498
+ ))
499
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
500
+ 'nullable' => true
501
+ ))
502
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
503
+ 'nullable' => true
504
+ ))
505
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
506
+ 'nullable' => true
507
+ ))
508
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
509
+ 'nullable' => true
510
+ ))
511
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
512
+ 'nullable' => true
513
+ ))
514
+ ->addForeignKey(
515
+ $this->getFkName('shipperhq_shipper/quote_packages', 'address_id', 'sales/quote_address', 'address_id'),
516
+ 'address_id',
517
+ $this->getTable('sales/quote_address'),
518
+ 'address_id',
519
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
520
+ )
521
+ ;
522
+ $this->getConnection()->createTable($table);
523
+ }
524
+
525
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_package_items'))) {
526
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_package_items'));
527
+
528
+ $table
529
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
530
+ 'nullable' => false,
531
+ ))
532
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
533
+ 'nullable' => false,
534
+ ))
535
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
536
+ 'nullable' => true
537
+ ))
538
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
539
+ 'nullable' => true
540
+ ))
541
+ ->addForeignKey(
542
+ $this->getFkName('shipperhq_shipper/quote_package_items', 'package_id', 'shipperhq_shipper/quote_packages', 'package_id'),
543
+ 'package_id',
544
+ $this->getTable('shipperhq_shipper/quote_packages'),
545
+ 'package_id',
546
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
547
+ )
548
+ ;
549
+ $this->getConnection()->createTable($table);
550
+ }
551
+
552
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_packages'))) {
553
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_packages'));
554
+
555
+ $table
556
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
557
+ 'primary' => true,
558
+ 'nullable' => false,
559
+ 'unsigned' => true,
560
+ 'auto_increment' => true
561
+ ))
562
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
563
+ 'nullable' => false,
564
+ 'unsigned' => true
565
+ ))
566
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
567
+ 'nullable' => false,
568
+ ))
569
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
570
+ 'nullable' => false,
571
+ ))
572
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
573
+ 'nullable' => true
574
+ ))
575
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
576
+ 'nullable' => true
577
+ ))
578
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
579
+ 'nullable' => true
580
+ ))
581
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
582
+ 'nullable' => true
583
+ ))
584
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
585
+ 'nullable' => true
586
+ ))
587
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
588
+ 'nullable' => true
589
+ ))
590
+ ->addForeignKey(
591
+ $this->getFkName('shipperhq_shipper/order_packages', 'order_id', 'sales/order', 'entity_id'),
592
+ 'order_id',
593
+ $this->getTable('sales/order'),
594
+ 'entity_id',
595
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
596
+ )
597
+ ;
598
+ $this->getConnection()->createTable($table);
599
+ }
600
+
601
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_package_items'))) {
602
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_package_items'));
603
+
604
+ $table
605
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
606
+ 'nullable' => false,
607
+ 'unsigned' => true,
608
+ ))
609
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
610
+ 'nullable' => false,
611
+ ))
612
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
613
+ 'nullable' => true
614
+ ))
615
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
616
+ 'nullable' => true
617
+ ))
618
+ ->addForeignKey(
619
+ $this->getFkName('shipperhq_shipper/order_package_items', 'package_id', 'shipperhq_shipper/order_packages', 'package_id'),
620
+ 'package_id',
621
+ $this->getTable('shipperhq_shipper/order_packages'),
622
+ 'package_id',
623
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
624
+ )
625
+ ;
626
+ $this->getConnection()->createTable($table);
627
+ }
628
+
629
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.20.php ADDED
@@ -0,0 +1,634 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/attributeupdate'))) {
8
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/attributeupdate'));
9
+
10
+ $table
11
+ ->addColumn('synch_id', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array(
12
+ 'primary' => true,
13
+ 'nullable' => false,
14
+ 'unsigned' => true,
15
+ 'auto_increment' => true
16
+ ))
17
+ ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 0, array(
18
+ 'nullable' => false,
19
+ 'unsigned' => true,
20
+ ))
21
+ ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
22
+ 'nullable' => false,
23
+ ))
24
+ ->addColumn('attribute_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
25
+ 'nullable' => false,
26
+ ))
27
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
28
+ 'nullable' => false,
29
+ ))
30
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
31
+ 'nullable' => false,
32
+ ))
33
+ ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
34
+ 'nullable' => false,
35
+ ))
36
+ ;
37
+ $this->getConnection()->createTable($table);
38
+ }
39
+
40
+ /* ------ shipperhq_shipping_group -------- */
41
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_group', array(
42
+ 'type' => 'varchar',
43
+ 'backend' => 'eav/entity_attribute_backend_array',
44
+ 'input' => 'multiselect',
45
+ 'label' => 'Shipping Group',
46
+ 'global' => false,
47
+ 'visible' => 1,
48
+ 'required' => 0,
49
+ 'visible_on_front' => 0,
50
+ 'is_html_allowed_on_front' => 0,
51
+ 'searchable' => 0,
52
+ 'filterable' => 0,
53
+ 'comparable' => 0,
54
+ 'unique' => false,
55
+ 'user_defined' => true,
56
+ 'used_in_product_listing' => false
57
+ ));
58
+
59
+ /* ------ shipperhq_warehouse -------- */
60
+ $this->addAttribute('catalog_product', 'shipperhq_warehouse', array(
61
+ 'type' => 'text',
62
+ 'backend' => 'eav/entity_attribute_backend_array',
63
+ 'input' => 'multiselect',
64
+ 'label' => 'Origin',
65
+ 'global' => false,
66
+ 'visible' => 1,
67
+ 'required' => 0,
68
+ 'visible_on_front' => 0,
69
+ 'is_html_allowed_on_front' => 0,
70
+ 'searchable' => 0,
71
+ 'filterable' => 0,
72
+ 'comparable' => 0,
73
+ 'unique' => false,
74
+ 'user_defined' => true,
75
+ 'used_in_product_listing' => false
76
+ ));
77
+
78
+ /* ------ shipperhq_shipping_qty -------- */
79
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_qty', array(
80
+ 'type' => 'int',
81
+ 'input' => 'text',
82
+ 'label' => 'Shipping Qty',
83
+ 'global' => false,
84
+ 'visible' => 1,
85
+ 'required' => 0,
86
+ 'visible_on_front' => 0,
87
+ 'is_html_allowed_on_front' => 0,
88
+ 'searchable' => 0,
89
+ 'filterable' => 0,
90
+ 'comparable' => 0,
91
+ 'unique' => false,
92
+ 'user_defined' => true,
93
+ 'used_in_product_listing' => false
94
+ ));
95
+
96
+ /* ------ shipperhq_shipping_fee -------- */
97
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_fee', array(
98
+ 'type' => 'decimal',
99
+ 'input' => 'price',
100
+ 'label' => 'Shipping Fee',
101
+ 'global' => false,
102
+ 'visible' => 1,
103
+ 'required' => 0,
104
+ 'visible_on_front' => 0,
105
+ 'is_html_allowed_on_front' => 0,
106
+ 'searchable' => 0,
107
+ 'filterable' => 0,
108
+ 'comparable' => 0,
109
+ 'unique' => false,
110
+ 'user_defined' => true,
111
+ 'used_in_product_listing' => false
112
+ ));
113
+
114
+ /* ------ shipperhq_additional_price -------- */
115
+ $this->addAttribute('catalog_product', 'shipperhq_additional_price', array(
116
+ 'type' => 'decimal',
117
+ 'input' => 'price',
118
+ 'label' => 'Additional Price',
119
+ 'global' => false,
120
+ 'visible' => 1,
121
+ 'required' => 0,
122
+ 'visible_on_front' => 0,
123
+ 'is_html_allowed_on_front' => 0,
124
+ 'searchable' => 0,
125
+ 'filterable' => 0,
126
+ 'comparable' => 0,
127
+ 'unique' => false,
128
+ 'user_defined' => true,
129
+ 'used_in_product_listing' => false
130
+ ));
131
+
132
+ /* ------ shipperhq_handling_fee -------- */
133
+ $this->addAttribute('catalog_product', 'shipperhq_handling_fee', array(
134
+ 'type' => 'decimal',
135
+ 'input' => 'price',
136
+ 'label' => 'Handling Fee',
137
+ 'global' => false,
138
+ 'visible' => 1,
139
+ 'required' => 0,
140
+ 'visible_on_front' => 0,
141
+ 'is_html_allowed_on_front' => 0,
142
+ 'searchable' => 0,
143
+ 'filterable' => 0,
144
+ 'comparable' => 0,
145
+ 'unique' => false,
146
+ 'user_defined' => true,
147
+ 'used_in_product_listing' => false
148
+ ));
149
+
150
+ /* ------ shipperhq_carrier_code -------- */
151
+ $this->addAttribute('catalog_product', 'shipperhq_carrier_code', array(
152
+ 'type' => 'text',
153
+ 'input' => 'text',
154
+ 'label' => 'Carrier Code',
155
+ 'global' => false,
156
+ 'visible' => 1,
157
+ 'required' => 0,
158
+ 'visible_on_front' => 0,
159
+ 'is_html_allowed_on_front' => 0,
160
+ 'searchable' => 0,
161
+ 'filterable' => 0,
162
+ 'comparable' => 0,
163
+ 'unique' => false,
164
+ 'user_defined' => true,
165
+ 'used_in_product_listing' => false
166
+ ));
167
+
168
+ /* ------ shipperhq_volume_weight -------- */
169
+ $this->addAttribute('catalog_product', 'shipperhq_volume_weight', array(
170
+ 'type' => 'decimal',
171
+ 'input' => 'text',
172
+ 'label' => 'Volume Weight',
173
+ 'global' => false,
174
+ 'visible' => 1,
175
+ 'required' => 0,
176
+ 'visible_on_front' => 0,
177
+ 'is_html_allowed_on_front' => 0,
178
+ 'searchable' => 0,
179
+ 'filterable' => 0,
180
+ 'comparable' => 0,
181
+ 'unique' => false,
182
+ 'user_defined' => true,
183
+ 'used_in_product_listing' => false
184
+ ));
185
+
186
+ /* ------ shipperhq_declared_value -------- */
187
+ $this->addAttribute('catalog_product', 'shipperhq_declared_value', array(
188
+ 'type' => 'decimal',
189
+ 'input' => 'price',
190
+ 'label' => 'Declared Value',
191
+ 'global' => false,
192
+ 'visible' => 1,
193
+ 'required' => 0,
194
+ 'visible_on_front' => 0,
195
+ 'is_html_allowed_on_front' => 0,
196
+ 'searchable' => 0,
197
+ 'filterable' => 0,
198
+ 'comparable' => 0,
199
+ 'unique' => false,
200
+ 'user_defined' => true,
201
+ 'used_in_product_listing' => false,
202
+ 'note' => 'The deemed cost of this product for customs & insurance purposes'
203
+ ));
204
+
205
+ /* ------ ship_separately -------- */
206
+ $this->addAttribute('catalog_product', 'ship_separately', array(
207
+ 'type' => 'int',
208
+ 'input' => 'boolean',
209
+ 'label' => 'Ship Separately',
210
+ 'global' => false,
211
+ 'visible' => 1,
212
+ 'required' => 0,
213
+ 'visible_on_front' => 0,
214
+ 'is_html_allowed_on_front' => 0,
215
+ 'searchable' => 0,
216
+ 'filterable' => 0,
217
+ 'comparable' => 0,
218
+ 'unique' => false,
219
+ 'user_defined' => true,
220
+ 'used_in_product_listing' => false
221
+ ));
222
+
223
+ /* ------ shipperhq_dim_group -------- */
224
+ $this->addAttribute('catalog_product', 'shipperhq_dim_group', array(
225
+ 'type' => 'varchar',
226
+ 'input' => 'select',
227
+ 'label' => 'ShipperHQ Dimensional Rule Group',
228
+ 'backend' => 'eav/entity_attribute_backend_array',
229
+ 'global' => false,
230
+ 'visible' => 1,
231
+ 'required' => 0,
232
+ 'visible_on_front' => 0,
233
+ 'is_html_allowed_on_front' => 0,
234
+ 'searchable' => 0,
235
+ 'filterable' => 0,
236
+ 'comparable' => 0,
237
+ 'unique' => false,
238
+ 'user_defined' => true,
239
+ 'used_in_product_listing' => false
240
+ ));
241
+
242
+ /* ------ ship_length -------- */
243
+ $this->addAttribute('catalog_product', 'ship_length', array(
244
+ 'type' => 'decimal',
245
+ 'input' => 'text',
246
+ 'label' => 'Dimension Length',
247
+ 'global' => false,
248
+ 'visible' => 1,
249
+ 'required' => 0,
250
+ 'visible_on_front' => 0,
251
+ 'is_html_allowed_on_front' => 0,
252
+ 'searchable' => 0,
253
+ 'filterable' => 0,
254
+ 'comparable' => 0,
255
+ 'unique' => false,
256
+ 'user_defined' => true,
257
+ 'used_in_product_listing' => false
258
+ ));
259
+
260
+ /* ------ ship_width -------- */
261
+ $this->addAttribute('catalog_product', 'ship_width', array(
262
+ 'type' => 'decimal',
263
+ 'input' => 'text',
264
+ 'label' => 'Dimension Width',
265
+ 'global' => false,
266
+ 'visible' => 1,
267
+ 'required' => 0,
268
+ 'visible_on_front' => 0,
269
+ 'is_html_allowed_on_front' => 0,
270
+ 'searchable' => 0,
271
+ 'filterable' => 0,
272
+ 'comparable' => 0,
273
+ 'unique' => false,
274
+ 'user_defined' => true,
275
+ 'used_in_product_listing' => false
276
+ ));
277
+
278
+ /* ------ ship_height -------- */
279
+ $this->addAttribute('catalog_product', 'ship_height', array(
280
+ 'type' => 'decimal',
281
+ 'input' => 'text',
282
+ 'label' => 'Dimension Height',
283
+ 'global' => false,
284
+ 'visible' => 1,
285
+ 'required' => 0,
286
+ 'visible_on_front' => 0,
287
+ 'is_html_allowed_on_front' => 0,
288
+ 'searchable' => 0,
289
+ 'filterable' => 0,
290
+ 'comparable' => 0,
291
+ 'unique' => false,
292
+ 'user_defined' => true,
293
+ 'used_in_product_listing' => false
294
+ ));
295
+
296
+ /* ------ shipperhq_poss_boxes -------- */
297
+ $this->addAttribute('catalog_product', 'shipperhq_poss_boxes', array(
298
+ 'type' => 'varchar',
299
+ 'backend' => 'eav/entity_attribute_backend_array',
300
+ 'input' => 'multiselect',
301
+ 'label' => 'Possible Packing Boxes',
302
+ 'global' => false,
303
+ 'visible' => 1,
304
+ 'required' => 0,
305
+ 'visible_on_front' => 0,
306
+ 'is_html_allowed_on_front' => 0,
307
+ 'searchable' => 0,
308
+ 'filterable' => 0,
309
+ 'comparable' => 0,
310
+ 'unique' => false,
311
+ 'user_defined' => true,
312
+ 'used_in_product_listing' => false
313
+ ));
314
+
315
+ /* ------ ship_box_tolerance -------- */
316
+ $this->addAttribute('catalog_product', 'ship_box_tolerance', array(
317
+ 'type' => 'int',
318
+ 'input' => 'text',
319
+ 'label' => 'Box Tolerance',
320
+ 'global' => false,
321
+ 'visible' => 1,
322
+ 'required' => 0,
323
+ 'visible_on_front' => 0,
324
+ 'is_html_allowed_on_front' => 0,
325
+ 'searchable' => 0,
326
+ 'filterable' => 0,
327
+ 'comparable' => 0,
328
+ 'unique' => false,
329
+ 'used_in_product_listing' => false,
330
+ 'user_defined' => true,
331
+ 'note' => 'Note: Ignore if unsure'
332
+ ));
333
+
334
+ /*
335
+ *
336
+ *
337
+ *
338
+ */
339
+
340
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
341
+
342
+ $attributeSetArr = $installer->getAllAttributeSetIds($entityTypeId);
343
+
344
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Splitrates')) {
345
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1', 'shipperhq_warehouse' => '10');
346
+ }
347
+ else {
348
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
349
+ }
350
+ $dimAttributeCodes = array('ship_separately' => '2',
351
+ 'shipperhq_dim_group' => '1',
352
+ 'ship_length' => '10',
353
+ 'ship_width' => '11',
354
+ 'ship_height' => '12',
355
+ 'shipperhq_poss_boxes' => '20',
356
+ );
357
+
358
+ foreach ($attributeSetArr as $attributeSetId) {
359
+
360
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
361
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
362
+
363
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
364
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
365
+
366
+ foreach($stdAttributeCodes as $code => $sort) {
367
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
368
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
369
+ }
370
+
371
+ foreach($dimAttributeCodes as $code => $sort) {
372
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
373
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
374
+ }
375
+
376
+ };
377
+
378
+
379
+
380
+ $text = Mage::helper('wsalogger')->getNewVersion() > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : 'text';
381
+
382
+ $isCheckout = array(
383
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
384
+ 'comment' => 'Shipperhq Shipper',
385
+ 'nullable' => 'false',
386
+ 'default' => '0'
387
+ );
388
+
389
+ $carrierType = array(
390
+ 'type' => $text,
391
+ 'comment' => 'Shipperhq Carrier Type',
392
+ 'nullable' => 'true',
393
+ );
394
+
395
+ $dispatchDate = array(
396
+ 'type' => $text,
397
+ 'length' => 20,
398
+ 'comment' => 'Dispatch Date',
399
+ 'nullable' => 'true');
400
+
401
+ $deliveryDate = array(
402
+ 'type' => $text,
403
+ 'length' => 20,
404
+ 'comment' => 'Expected Delivery',
405
+ 'nullable' => 'true');
406
+
407
+ $carrierNotice = array(
408
+ 'type' => $text,
409
+ 'comment' => 'Shipperhq Carrier Notice',
410
+ 'nullable' => 'true',
411
+ );
412
+
413
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'is_checkout')){
414
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
415
+ }
416
+
417
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carrier_type')){
418
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
419
+ }
420
+
421
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'dispatch_date')){
422
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
423
+ }
424
+
425
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'delivery_date')){
426
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
427
+ }
428
+
429
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type')){
430
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
431
+ }
432
+
433
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'dispatch_date')){
434
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
435
+ }
436
+
437
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'delivery_date')){
438
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
439
+ }
440
+
441
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice')){
442
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
443
+ }
444
+
445
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carrier_type')){
446
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
447
+ }
448
+
449
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'dispatch_date')){
450
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
451
+ }
452
+
453
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'delivery_date')){
454
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
455
+ }
456
+
457
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/storage'))) {
458
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/storage'));
459
+
460
+ $table
461
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
462
+ 'primary' => true,
463
+ 'nullable' => false,
464
+ 'unsigned' => true
465
+ ))
466
+ ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '512k', array('nullable' => false))
467
+ ->addForeignKey(
468
+ $this->getFkName('shipperhq_shipper/storage', 'quote_id', 'sales/quote', 'entity_id'),
469
+ 'quote_id',
470
+ $this->getTable('sales/quote'),
471
+ 'entity_id',
472
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
473
+ )
474
+ ;
475
+ $this->getConnection()->createTable($table);
476
+ }
477
+
478
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_packages'))) {
479
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_packages'));
480
+
481
+ $table
482
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
483
+ 'primary' => true,
484
+ 'nullable' => false,
485
+ 'unsigned' => true,
486
+ 'auto_increment' => true
487
+ ))
488
+ ->addColumn('address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
489
+ 'nullable' => false,
490
+ 'unsigned' => true
491
+ ))
492
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
493
+ 'nullable' => false,
494
+ ))
495
+ ->addColumn('carrier_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
496
+ 'nullable' => false,
497
+ ))
498
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
499
+ 'nullable' => false,
500
+ ))
501
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
502
+ 'nullable' => true
503
+ ))
504
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
505
+ 'nullable' => true
506
+ ))
507
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
508
+ 'nullable' => true
509
+ ))
510
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
511
+ 'nullable' => true
512
+ ))
513
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
514
+ 'nullable' => true
515
+ ))
516
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
517
+ 'nullable' => true
518
+ ))
519
+ ->addForeignKey(
520
+ $this->getFkName('shipperhq_shipper/quote_packages', 'address_id', 'sales/quote_address', 'address_id'),
521
+ 'address_id',
522
+ $this->getTable('sales/quote_address'),
523
+ 'address_id',
524
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
525
+ )
526
+ ;
527
+ $this->getConnection()->createTable($table);
528
+ }
529
+
530
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_package_items'))) {
531
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_package_items'));
532
+
533
+ $table
534
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
535
+ 'nullable' => false,
536
+ ))
537
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
538
+ 'nullable' => false,
539
+ ))
540
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
541
+ 'nullable' => true
542
+ ))
543
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
544
+ 'nullable' => true
545
+ ))
546
+ ->addForeignKey(
547
+ $this->getFkName('shipperhq_shipper/quote_package_items', 'package_id', 'shipperhq_shipper/quote_packages', 'package_id'),
548
+ 'package_id',
549
+ $this->getTable('shipperhq_shipper/quote_packages'),
550
+ 'package_id',
551
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
552
+ )
553
+ ;
554
+ $this->getConnection()->createTable($table);
555
+ }
556
+
557
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_packages'))) {
558
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_packages'));
559
+
560
+ $table
561
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
562
+ 'primary' => true,
563
+ 'nullable' => false,
564
+ 'unsigned' => true,
565
+ 'auto_increment' => true
566
+ ))
567
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
568
+ 'nullable' => false,
569
+ 'unsigned' => true
570
+ ))
571
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
572
+ 'nullable' => false,
573
+ ))
574
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
575
+ 'nullable' => false,
576
+ ))
577
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
578
+ 'nullable' => true
579
+ ))
580
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
581
+ 'nullable' => true
582
+ ))
583
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
584
+ 'nullable' => true
585
+ ))
586
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
587
+ 'nullable' => true
588
+ ))
589
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
590
+ 'nullable' => true
591
+ ))
592
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
593
+ 'nullable' => true
594
+ ))
595
+ ->addForeignKey(
596
+ $this->getFkName('shipperhq_shipper/order_packages', 'order_id', 'sales/order', 'entity_id'),
597
+ 'order_id',
598
+ $this->getTable('sales/order'),
599
+ 'entity_id',
600
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
601
+ )
602
+ ;
603
+ $this->getConnection()->createTable($table);
604
+ }
605
+
606
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_package_items'))) {
607
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_package_items'));
608
+
609
+ $table
610
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
611
+ 'nullable' => false,
612
+ 'unsigned' => true,
613
+ ))
614
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
615
+ 'nullable' => false,
616
+ ))
617
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
618
+ 'nullable' => true
619
+ ))
620
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
621
+ 'nullable' => true
622
+ ))
623
+ ->addForeignKey(
624
+ $this->getFkName('shipperhq_shipper/order_package_items', 'package_id', 'shipperhq_shipper/order_packages', 'package_id'),
625
+ 'package_id',
626
+ $this->getTable('shipperhq_shipper/order_packages'),
627
+ 'package_id',
628
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
629
+ )
630
+ ;
631
+ $this->getConnection()->createTable($table);
632
+ }
633
+
634
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.21.php ADDED
@@ -0,0 +1,645 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/attributeupdate'))) {
8
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/attributeupdate'));
9
+
10
+ $table
11
+ ->addColumn('synch_id', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array(
12
+ 'primary' => true,
13
+ 'nullable' => false,
14
+ 'unsigned' => true,
15
+ 'auto_increment' => true
16
+ ))
17
+ ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 0, array(
18
+ 'nullable' => false,
19
+ 'unsigned' => true,
20
+ ))
21
+ ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
22
+ 'nullable' => false,
23
+ ))
24
+ ->addColumn('attribute_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
25
+ 'nullable' => false,
26
+ ))
27
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
28
+ 'nullable' => false,
29
+ ))
30
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
31
+ 'nullable' => false,
32
+ ))
33
+ ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
34
+ 'nullable' => false,
35
+ ))
36
+ ;
37
+ $this->getConnection()->createTable($table);
38
+ }
39
+
40
+ /* ------ shipperhq_shipping_group -------- */
41
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_group', array(
42
+ 'type' => 'varchar',
43
+ 'backend' => 'eav/entity_attribute_backend_array',
44
+ 'input' => 'multiselect',
45
+ 'label' => 'Shipping Group',
46
+ 'global' => false,
47
+ 'visible' => 1,
48
+ 'required' => 0,
49
+ 'visible_on_front' => 0,
50
+ 'is_html_allowed_on_front' => 0,
51
+ 'searchable' => 0,
52
+ 'filterable' => 0,
53
+ 'comparable' => 0,
54
+ 'unique' => false,
55
+ 'user_defined' => true,
56
+ 'used_in_product_listing' => false
57
+ ));
58
+
59
+ /* ------ shipperhq_warehouse -------- */
60
+ $this->addAttribute('catalog_product', 'shipperhq_warehouse', array(
61
+ 'type' => 'text',
62
+ 'backend' => 'eav/entity_attribute_backend_array',
63
+ 'input' => 'multiselect',
64
+ 'label' => 'Origin',
65
+ 'global' => false,
66
+ 'visible' => 1,
67
+ 'required' => 0,
68
+ 'visible_on_front' => 0,
69
+ 'is_html_allowed_on_front' => 0,
70
+ 'searchable' => 0,
71
+ 'filterable' => 0,
72
+ 'comparable' => 0,
73
+ 'unique' => false,
74
+ 'user_defined' => true,
75
+ 'used_in_product_listing' => false
76
+ ));
77
+
78
+ /* ------ shipperhq_shipping_qty -------- */
79
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_qty', array(
80
+ 'type' => 'int',
81
+ 'input' => 'text',
82
+ 'label' => 'Shipping Qty',
83
+ 'global' => false,
84
+ 'visible' => 1,
85
+ 'required' => 0,
86
+ 'visible_on_front' => 0,
87
+ 'is_html_allowed_on_front' => 0,
88
+ 'searchable' => 0,
89
+ 'filterable' => 0,
90
+ 'comparable' => 0,
91
+ 'unique' => false,
92
+ 'user_defined' => true,
93
+ 'used_in_product_listing' => false
94
+ ));
95
+
96
+ /* ------ shipperhq_shipping_fee -------- */
97
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_fee', array(
98
+ 'type' => 'decimal',
99
+ 'input' => 'price',
100
+ 'label' => 'Shipping Fee',
101
+ 'global' => false,
102
+ 'visible' => 1,
103
+ 'required' => 0,
104
+ 'visible_on_front' => 0,
105
+ 'is_html_allowed_on_front' => 0,
106
+ 'searchable' => 0,
107
+ 'filterable' => 0,
108
+ 'comparable' => 0,
109
+ 'unique' => false,
110
+ 'user_defined' => true,
111
+ 'used_in_product_listing' => false
112
+ ));
113
+
114
+ /* ------ shipperhq_additional_price -------- */
115
+ $this->addAttribute('catalog_product', 'shipperhq_additional_price', array(
116
+ 'type' => 'decimal',
117
+ 'input' => 'price',
118
+ 'label' => 'Additional Price',
119
+ 'global' => false,
120
+ 'visible' => 1,
121
+ 'required' => 0,
122
+ 'visible_on_front' => 0,
123
+ 'is_html_allowed_on_front' => 0,
124
+ 'searchable' => 0,
125
+ 'filterable' => 0,
126
+ 'comparable' => 0,
127
+ 'unique' => false,
128
+ 'user_defined' => true,
129
+ 'used_in_product_listing' => false
130
+ ));
131
+
132
+ /* ------ shipperhq_handling_fee -------- */
133
+ $this->addAttribute('catalog_product', 'shipperhq_handling_fee', array(
134
+ 'type' => 'decimal',
135
+ 'input' => 'price',
136
+ 'label' => 'Handling Fee',
137
+ 'global' => false,
138
+ 'visible' => 1,
139
+ 'required' => 0,
140
+ 'visible_on_front' => 0,
141
+ 'is_html_allowed_on_front' => 0,
142
+ 'searchable' => 0,
143
+ 'filterable' => 0,
144
+ 'comparable' => 0,
145
+ 'unique' => false,
146
+ 'user_defined' => true,
147
+ 'used_in_product_listing' => false
148
+ ));
149
+
150
+ /* ------ shipperhq_carrier_code -------- */
151
+ $this->addAttribute('catalog_product', 'shipperhq_carrier_code', array(
152
+ 'type' => 'text',
153
+ 'input' => 'text',
154
+ 'label' => 'Carrier Code',
155
+ 'global' => false,
156
+ 'visible' => 1,
157
+ 'required' => 0,
158
+ 'visible_on_front' => 0,
159
+ 'is_html_allowed_on_front' => 0,
160
+ 'searchable' => 0,
161
+ 'filterable' => 0,
162
+ 'comparable' => 0,
163
+ 'unique' => false,
164
+ 'user_defined' => true,
165
+ 'used_in_product_listing' => false
166
+ ));
167
+
168
+ /* ------ shipperhq_volume_weight -------- */
169
+ $this->addAttribute('catalog_product', 'shipperhq_volume_weight', array(
170
+ 'type' => 'decimal',
171
+ 'input' => 'text',
172
+ 'label' => 'Volume Weight',
173
+ 'global' => false,
174
+ 'visible' => 1,
175
+ 'required' => 0,
176
+ 'visible_on_front' => 0,
177
+ 'is_html_allowed_on_front' => 0,
178
+ 'searchable' => 0,
179
+ 'filterable' => 0,
180
+ 'comparable' => 0,
181
+ 'unique' => false,
182
+ 'user_defined' => true,
183
+ 'used_in_product_listing' => false,
184
+ 'note' => 'This value is only used in conjunction with shipping filters'
185
+ ));
186
+
187
+ /* ------ shipperhq_declared_value -------- */
188
+ $this->addAttribute('catalog_product', 'shipperhq_declared_value', array(
189
+ 'type' => 'decimal',
190
+ 'input' => 'price',
191
+ 'label' => 'Declared Value',
192
+ 'global' => false,
193
+ 'visible' => 1,
194
+ 'required' => 0,
195
+ 'visible_on_front' => 0,
196
+ 'is_html_allowed_on_front' => 0,
197
+ 'searchable' => 0,
198
+ 'filterable' => 0,
199
+ 'comparable' => 0,
200
+ 'unique' => false,
201
+ 'user_defined' => true,
202
+ 'used_in_product_listing' => false,
203
+ 'note' => 'The deemed cost of this product for customs & insurance purposes'
204
+ ));
205
+
206
+ /* ------ ship_separately -------- */
207
+ $this->addAttribute('catalog_product', 'ship_separately', array(
208
+ 'type' => 'int',
209
+ 'input' => 'boolean',
210
+ 'label' => 'Ship Separately',
211
+ 'global' => false,
212
+ 'visible' => 1,
213
+ 'required' => 0,
214
+ 'visible_on_front' => 0,
215
+ 'is_html_allowed_on_front' => 0,
216
+ 'searchable' => 0,
217
+ 'filterable' => 0,
218
+ 'comparable' => 0,
219
+ 'unique' => false,
220
+ 'user_defined' => true,
221
+ 'used_in_product_listing' => false
222
+ ));
223
+
224
+ /* ------ shipperhq_dim_group -------- */
225
+ $this->addAttribute('catalog_product', 'shipperhq_dim_group', array(
226
+ 'type' => 'varchar',
227
+ 'input' => 'select',
228
+ 'label' => 'ShipperHQ Dimensional Rule Group',
229
+ 'backend' => 'eav/entity_attribute_backend_array',
230
+ 'global' => false,
231
+ 'visible' => 1,
232
+ 'required' => 0,
233
+ 'visible_on_front' => 0,
234
+ 'is_html_allowed_on_front' => 0,
235
+ 'searchable' => 0,
236
+ 'filterable' => 0,
237
+ 'comparable' => 0,
238
+ 'unique' => false,
239
+ 'user_defined' => true,
240
+ 'used_in_product_listing' => false
241
+ ));
242
+
243
+ /* ------ ship_length -------- */
244
+ $this->addAttribute('catalog_product', 'ship_length', array(
245
+ 'type' => 'decimal',
246
+ 'input' => 'text',
247
+ 'label' => 'Dimension Length',
248
+ 'global' => false,
249
+ 'visible' => 1,
250
+ 'required' => 0,
251
+ 'visible_on_front' => 0,
252
+ 'is_html_allowed_on_front' => 0,
253
+ 'searchable' => 0,
254
+ 'filterable' => 0,
255
+ 'comparable' => 0,
256
+ 'unique' => false,
257
+ 'user_defined' => true,
258
+ 'used_in_product_listing' => false
259
+ ));
260
+
261
+ /* ------ ship_width -------- */
262
+ $this->addAttribute('catalog_product', 'ship_width', array(
263
+ 'type' => 'decimal',
264
+ 'input' => 'text',
265
+ 'label' => 'Dimension Width',
266
+ 'global' => false,
267
+ 'visible' => 1,
268
+ 'required' => 0,
269
+ 'visible_on_front' => 0,
270
+ 'is_html_allowed_on_front' => 0,
271
+ 'searchable' => 0,
272
+ 'filterable' => 0,
273
+ 'comparable' => 0,
274
+ 'unique' => false,
275
+ 'user_defined' => true,
276
+ 'used_in_product_listing' => false
277
+ ));
278
+
279
+ /* ------ ship_height -------- */
280
+ $this->addAttribute('catalog_product', 'ship_height', array(
281
+ 'type' => 'decimal',
282
+ 'input' => 'text',
283
+ 'label' => 'Dimension Height',
284
+ 'global' => false,
285
+ 'visible' => 1,
286
+ 'required' => 0,
287
+ 'visible_on_front' => 0,
288
+ 'is_html_allowed_on_front' => 0,
289
+ 'searchable' => 0,
290
+ 'filterable' => 0,
291
+ 'comparable' => 0,
292
+ 'unique' => false,
293
+ 'user_defined' => true,
294
+ 'used_in_product_listing' => false
295
+ ));
296
+
297
+ /* ------ shipperhq_poss_boxes -------- */
298
+ $this->addAttribute('catalog_product', 'shipperhq_poss_boxes', array(
299
+ 'type' => 'varchar',
300
+ 'backend' => 'eav/entity_attribute_backend_array',
301
+ 'input' => 'multiselect',
302
+ 'label' => 'Possible Packing Boxes',
303
+ 'global' => false,
304
+ 'visible' => 1,
305
+ 'required' => 0,
306
+ 'visible_on_front' => 0,
307
+ 'is_html_allowed_on_front' => 0,
308
+ 'searchable' => 0,
309
+ 'filterable' => 0,
310
+ 'comparable' => 0,
311
+ 'unique' => false,
312
+ 'user_defined' => true,
313
+ 'used_in_product_listing' => false
314
+ ));
315
+
316
+ /* ------ ship_box_tolerance -------- */
317
+ $this->addAttribute('catalog_product', 'ship_box_tolerance', array(
318
+ 'type' => 'int',
319
+ 'input' => 'text',
320
+ 'label' => 'Box Tolerance',
321
+ 'global' => false,
322
+ 'visible' => 1,
323
+ 'required' => 0,
324
+ 'visible_on_front' => 0,
325
+ 'is_html_allowed_on_front' => 0,
326
+ 'searchable' => 0,
327
+ 'filterable' => 0,
328
+ 'comparable' => 0,
329
+ 'unique' => false,
330
+ 'used_in_product_listing' => false,
331
+ 'user_defined' => true,
332
+ 'note' => 'Note: Ignore if unsure'
333
+ ));
334
+
335
+ /*
336
+ *
337
+ *
338
+ *
339
+ */
340
+
341
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
342
+
343
+ $attributeSetArr = $installer->getAllAttributeSetIds($entityTypeId);
344
+
345
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Splitrates')) {
346
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1', 'shipperhq_warehouse' => '10');
347
+ }
348
+ else {
349
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
350
+ }
351
+ $dimAttributeCodes = array('ship_separately' => '2',
352
+ 'shipperhq_dim_group' => '1',
353
+ 'ship_length' => '10',
354
+ 'ship_width' => '11',
355
+ 'ship_height' => '12',
356
+ 'shipperhq_poss_boxes' => '20',
357
+ );
358
+
359
+ foreach ($attributeSetArr as $attributeSetId) {
360
+
361
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
362
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
363
+
364
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
365
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
366
+
367
+ foreach($stdAttributeCodes as $code => $sort) {
368
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
369
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
370
+ }
371
+
372
+ foreach($dimAttributeCodes as $code => $sort) {
373
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
374
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
375
+ }
376
+
377
+ };
378
+
379
+
380
+
381
+ $text = Mage::helper('wsalogger')->getNewVersion() > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : 'text';
382
+
383
+ $isCheckout = array(
384
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
385
+ 'comment' => 'Shipperhq Shipper',
386
+ 'nullable' => 'false',
387
+ 'default' => '0'
388
+ );
389
+
390
+ $carrierType = array(
391
+ 'type' => $text,
392
+ 'comment' => 'Shipperhq Carrier Type',
393
+ 'nullable' => 'true',
394
+ );
395
+
396
+ $dispatchDate = array(
397
+ 'type' => $text,
398
+ 'length' => 20,
399
+ 'comment' => 'Dispatch Date',
400
+ 'nullable' => 'true');
401
+
402
+ $deliveryDate = array(
403
+ 'type' => $text,
404
+ 'length' => 20,
405
+ 'comment' => 'Expected Delivery',
406
+ 'nullable' => 'true');
407
+
408
+ $carrierNotice = array(
409
+ 'type' => $text,
410
+ 'comment' => 'Shipperhq Carrier Notice',
411
+ 'nullable' => 'true',
412
+ );
413
+
414
+ $customDescription = array(
415
+ 'type' => $text,
416
+ 'comment' => 'Shipperhq Custom Description',
417
+ 'nullable' => 'true',
418
+ );
419
+
420
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'is_checkout')){
421
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
422
+ }
423
+
424
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carrier_type')){
425
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
426
+ }
427
+
428
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'dispatch_date')){
429
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
430
+ }
431
+
432
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'delivery_date')){
433
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
434
+ }
435
+
436
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type')){
437
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
438
+ }
439
+
440
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'dispatch_date')){
441
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
442
+ }
443
+
444
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'delivery_date')){
445
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
446
+ }
447
+
448
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice')){
449
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
450
+ }
451
+
452
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'custom_description')){
453
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'custom_description', $customDescription);
454
+ }
455
+
456
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carrier_type')){
457
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
458
+ }
459
+
460
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'dispatch_date')){
461
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
462
+ }
463
+
464
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'delivery_date')){
465
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
466
+ }
467
+
468
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/storage'))) {
469
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/storage'));
470
+
471
+ $table
472
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
473
+ 'primary' => true,
474
+ 'nullable' => false,
475
+ 'unsigned' => true
476
+ ))
477
+ ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '512k', array('nullable' => false))
478
+ ->addForeignKey(
479
+ $this->getFkName('shipperhq_shipper/storage', 'quote_id', 'sales/quote', 'entity_id'),
480
+ 'quote_id',
481
+ $this->getTable('sales/quote'),
482
+ 'entity_id',
483
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
484
+ )
485
+ ;
486
+ $this->getConnection()->createTable($table);
487
+ }
488
+
489
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_packages'))) {
490
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_packages'));
491
+
492
+ $table
493
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
494
+ 'primary' => true,
495
+ 'nullable' => false,
496
+ 'unsigned' => true,
497
+ 'auto_increment' => true
498
+ ))
499
+ ->addColumn('address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
500
+ 'nullable' => false,
501
+ 'unsigned' => true
502
+ ))
503
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
504
+ 'nullable' => false,
505
+ ))
506
+ ->addColumn('carrier_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
507
+ 'nullable' => false,
508
+ ))
509
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
510
+ 'nullable' => false,
511
+ ))
512
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
513
+ 'nullable' => true
514
+ ))
515
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
516
+ 'nullable' => true
517
+ ))
518
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
519
+ 'nullable' => true
520
+ ))
521
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
522
+ 'nullable' => true
523
+ ))
524
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
525
+ 'nullable' => true
526
+ ))
527
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
528
+ 'nullable' => true
529
+ ))
530
+ ->addForeignKey(
531
+ $this->getFkName('shipperhq_shipper/quote_packages', 'address_id', 'sales/quote_address', 'address_id'),
532
+ 'address_id',
533
+ $this->getTable('sales/quote_address'),
534
+ 'address_id',
535
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
536
+ )
537
+ ;
538
+ $this->getConnection()->createTable($table);
539
+ }
540
+
541
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_package_items'))) {
542
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_package_items'));
543
+
544
+ $table
545
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
546
+ 'nullable' => false,
547
+ ))
548
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
549
+ 'nullable' => false,
550
+ ))
551
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
552
+ 'nullable' => true
553
+ ))
554
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
555
+ 'nullable' => true
556
+ ))
557
+ ->addForeignKey(
558
+ $this->getFkName('shipperhq_shipper/quote_package_items', 'package_id', 'shipperhq_shipper/quote_packages', 'package_id'),
559
+ 'package_id',
560
+ $this->getTable('shipperhq_shipper/quote_packages'),
561
+ 'package_id',
562
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
563
+ )
564
+ ;
565
+ $this->getConnection()->createTable($table);
566
+ }
567
+
568
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_packages'))) {
569
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_packages'));
570
+
571
+ $table
572
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
573
+ 'primary' => true,
574
+ 'nullable' => false,
575
+ 'unsigned' => true,
576
+ 'auto_increment' => true
577
+ ))
578
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
579
+ 'nullable' => false,
580
+ 'unsigned' => true
581
+ ))
582
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
583
+ 'nullable' => false,
584
+ ))
585
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
586
+ 'nullable' => false,
587
+ ))
588
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
589
+ 'nullable' => true
590
+ ))
591
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
592
+ 'nullable' => true
593
+ ))
594
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
595
+ 'nullable' => true
596
+ ))
597
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
598
+ 'nullable' => true
599
+ ))
600
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
601
+ 'nullable' => true
602
+ ))
603
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
604
+ 'nullable' => true
605
+ ))
606
+ ->addForeignKey(
607
+ $this->getFkName('shipperhq_shipper/order_packages', 'order_id', 'sales/order', 'entity_id'),
608
+ 'order_id',
609
+ $this->getTable('sales/order'),
610
+ 'entity_id',
611
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
612
+ )
613
+ ;
614
+ $this->getConnection()->createTable($table);
615
+ }
616
+
617
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_package_items'))) {
618
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_package_items'));
619
+
620
+ $table
621
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
622
+ 'nullable' => false,
623
+ 'unsigned' => true,
624
+ ))
625
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
626
+ 'nullable' => false,
627
+ ))
628
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
629
+ 'nullable' => true
630
+ ))
631
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
632
+ 'nullable' => true
633
+ ))
634
+ ->addForeignKey(
635
+ $this->getFkName('shipperhq_shipper/order_package_items', 'package_id', 'shipperhq_shipper/order_packages', 'package_id'),
636
+ 'package_id',
637
+ $this->getTable('shipperhq_shipper/order_packages'),
638
+ 'package_id',
639
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
640
+ )
641
+ ;
642
+ $this->getConnection()->createTable($table);
643
+ }
644
+
645
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.22.php ADDED
@@ -0,0 +1,649 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/attributeupdate'))) {
8
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/attributeupdate'));
9
+
10
+ $table
11
+ ->addColumn('synch_id', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array(
12
+ 'primary' => true,
13
+ 'nullable' => false,
14
+ 'unsigned' => true,
15
+ 'auto_increment' => true
16
+ ))
17
+ ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 0, array(
18
+ 'nullable' => false,
19
+ 'unsigned' => true,
20
+ ))
21
+ ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
22
+ 'nullable' => false,
23
+ ))
24
+ ->addColumn('attribute_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
25
+ 'nullable' => false,
26
+ ))
27
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
28
+ 'nullable' => false,
29
+ ))
30
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
31
+ 'nullable' => false,
32
+ ))
33
+ ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
34
+ 'nullable' => false,
35
+ ))
36
+ ;
37
+ $this->getConnection()->createTable($table);
38
+ }
39
+
40
+ /* ------ shipperhq_shipping_group -------- */
41
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_group', array(
42
+ 'type' => 'varchar',
43
+ 'backend' => 'eav/entity_attribute_backend_array',
44
+ 'input' => 'multiselect',
45
+ 'label' => 'Shipping Group',
46
+ 'global' => false,
47
+ 'visible' => 1,
48
+ 'required' => 0,
49
+ 'visible_on_front' => 0,
50
+ 'is_html_allowed_on_front' => 0,
51
+ 'searchable' => 0,
52
+ 'filterable' => 0,
53
+ 'comparable' => 0,
54
+ 'is_configurable' => 0,
55
+ 'unique' => false,
56
+ 'user_defined' => true,
57
+ 'used_in_product_listing' => false
58
+ ));
59
+
60
+ /* ------ shipperhq_warehouse -------- */
61
+ $this->addAttribute('catalog_product', 'shipperhq_warehouse', array(
62
+ 'type' => 'text',
63
+ 'backend' => 'eav/entity_attribute_backend_array',
64
+ 'input' => 'multiselect',
65
+ 'label' => 'Origin',
66
+ 'global' => false,
67
+ 'visible' => 1,
68
+ 'required' => 0,
69
+ 'visible_on_front' => 0,
70
+ 'is_html_allowed_on_front' => 0,
71
+ 'searchable' => 0,
72
+ 'filterable' => 0,
73
+ 'comparable' => 0,
74
+ 'is_configurable' => 0,
75
+ 'unique' => false,
76
+ 'user_defined' => true,
77
+ 'used_in_product_listing' => false
78
+ ));
79
+
80
+ /* ------ shipperhq_shipping_qty -------- */
81
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_qty', array(
82
+ 'type' => 'int',
83
+ 'input' => 'text',
84
+ 'label' => 'Shipping Qty',
85
+ 'global' => false,
86
+ 'visible' => 1,
87
+ 'required' => 0,
88
+ 'visible_on_front' => 0,
89
+ 'is_html_allowed_on_front' => 0,
90
+ 'searchable' => 0,
91
+ 'filterable' => 0,
92
+ 'comparable' => 0,
93
+ 'unique' => false,
94
+ 'user_defined' => true,
95
+ 'used_in_product_listing' => false
96
+ ));
97
+
98
+ /* ------ shipperhq_shipping_fee -------- */
99
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_fee', array(
100
+ 'type' => 'decimal',
101
+ 'input' => 'price',
102
+ 'label' => 'Shipping Fee',
103
+ 'global' => false,
104
+ 'visible' => 1,
105
+ 'required' => 0,
106
+ 'visible_on_front' => 0,
107
+ 'is_html_allowed_on_front' => 0,
108
+ 'searchable' => 0,
109
+ 'filterable' => 0,
110
+ 'comparable' => 0,
111
+ 'unique' => false,
112
+ 'user_defined' => true,
113
+ 'used_in_product_listing' => false
114
+ ));
115
+
116
+ /* ------ shipperhq_additional_price -------- */
117
+ $this->addAttribute('catalog_product', 'shipperhq_additional_price', array(
118
+ 'type' => 'decimal',
119
+ 'input' => 'price',
120
+ 'label' => 'Additional Price',
121
+ 'global' => false,
122
+ 'visible' => 1,
123
+ 'required' => 0,
124
+ 'visible_on_front' => 0,
125
+ 'is_html_allowed_on_front' => 0,
126
+ 'searchable' => 0,
127
+ 'filterable' => 0,
128
+ 'comparable' => 0,
129
+ 'unique' => false,
130
+ 'user_defined' => true,
131
+ 'used_in_product_listing' => false
132
+ ));
133
+
134
+ /* ------ shipperhq_handling_fee -------- */
135
+ $this->addAttribute('catalog_product', 'shipperhq_handling_fee', array(
136
+ 'type' => 'decimal',
137
+ 'input' => 'price',
138
+ 'label' => 'Handling Fee',
139
+ 'global' => false,
140
+ 'visible' => 1,
141
+ 'required' => 0,
142
+ 'visible_on_front' => 0,
143
+ 'is_html_allowed_on_front' => 0,
144
+ 'searchable' => 0,
145
+ 'filterable' => 0,
146
+ 'comparable' => 0,
147
+ 'unique' => false,
148
+ 'user_defined' => true,
149
+ 'used_in_product_listing' => false
150
+ ));
151
+
152
+ /* ------ shipperhq_carrier_code -------- */
153
+ $this->addAttribute('catalog_product', 'shipperhq_carrier_code', array(
154
+ 'type' => 'text',
155
+ 'input' => 'text',
156
+ 'label' => 'Carrier Code',
157
+ 'global' => false,
158
+ 'visible' => 1,
159
+ 'required' => 0,
160
+ 'visible_on_front' => 0,
161
+ 'is_html_allowed_on_front' => 0,
162
+ 'searchable' => 0,
163
+ 'filterable' => 0,
164
+ 'comparable' => 0,
165
+ 'unique' => false,
166
+ 'user_defined' => true,
167
+ 'used_in_product_listing' => false
168
+ ));
169
+
170
+ /* ------ shipperhq_volume_weight -------- */
171
+ $this->addAttribute('catalog_product', 'shipperhq_volume_weight', array(
172
+ 'type' => 'decimal',
173
+ 'input' => 'text',
174
+ 'label' => 'Volume Weight',
175
+ 'global' => false,
176
+ 'visible' => 1,
177
+ 'required' => 0,
178
+ 'visible_on_front' => 0,
179
+ 'is_html_allowed_on_front' => 0,
180
+ 'searchable' => 0,
181
+ 'filterable' => 0,
182
+ 'comparable' => 0,
183
+ 'unique' => false,
184
+ 'user_defined' => true,
185
+ 'used_in_product_listing' => false,
186
+ 'note' => 'This value is only used in conjunction with shipping filters'
187
+ ));
188
+
189
+ /* ------ shipperhq_declared_value -------- */
190
+ $this->addAttribute('catalog_product', 'shipperhq_declared_value', array(
191
+ 'type' => 'decimal',
192
+ 'input' => 'price',
193
+ 'label' => 'Declared Value',
194
+ 'global' => false,
195
+ 'visible' => 1,
196
+ 'required' => 0,
197
+ 'visible_on_front' => 0,
198
+ 'is_html_allowed_on_front' => 0,
199
+ 'searchable' => 0,
200
+ 'filterable' => 0,
201
+ 'comparable' => 0,
202
+ 'unique' => false,
203
+ 'user_defined' => true,
204
+ 'used_in_product_listing' => false,
205
+ 'note' => 'The deemed cost of this product for customs & insurance purposes'
206
+ ));
207
+
208
+ /* ------ ship_separately -------- */
209
+ $this->addAttribute('catalog_product', 'ship_separately', array(
210
+ 'type' => 'int',
211
+ 'input' => 'boolean',
212
+ 'label' => 'Ship Separately',
213
+ 'global' => false,
214
+ 'visible' => 1,
215
+ 'required' => 0,
216
+ 'visible_on_front' => 0,
217
+ 'is_html_allowed_on_front' => 0,
218
+ 'searchable' => 0,
219
+ 'filterable' => 0,
220
+ 'comparable' => 0,
221
+ 'unique' => false,
222
+ 'user_defined' => true,
223
+ 'used_in_product_listing' => false
224
+ ));
225
+
226
+ /* ------ shipperhq_dim_group -------- */
227
+ $this->addAttribute('catalog_product', 'shipperhq_dim_group', array(
228
+ 'type' => 'varchar',
229
+ 'input' => 'select',
230
+ 'label' => 'ShipperHQ Dimensional Rule Group',
231
+ 'backend' => 'eav/entity_attribute_backend_array',
232
+ 'global' => false,
233
+ 'visible' => 1,
234
+ 'required' => 0,
235
+ 'visible_on_front' => 0,
236
+ 'is_html_allowed_on_front' => 0,
237
+ 'searchable' => 0,
238
+ 'filterable' => 0,
239
+ 'comparable' => 0,
240
+ 'is_configurable' => 0,
241
+ 'unique' => false,
242
+ 'user_defined' => true,
243
+ 'used_in_product_listing' => false
244
+ ));
245
+
246
+ /* ------ ship_length -------- */
247
+ $this->addAttribute('catalog_product', 'ship_length', array(
248
+ 'type' => 'decimal',
249
+ 'input' => 'text',
250
+ 'label' => 'Dimension Length',
251
+ 'global' => false,
252
+ 'visible' => 1,
253
+ 'required' => 0,
254
+ 'visible_on_front' => 0,
255
+ 'is_html_allowed_on_front' => 0,
256
+ 'searchable' => 0,
257
+ 'filterable' => 0,
258
+ 'comparable' => 0,
259
+ 'unique' => false,
260
+ 'user_defined' => true,
261
+ 'used_in_product_listing' => false
262
+ ));
263
+
264
+ /* ------ ship_width -------- */
265
+ $this->addAttribute('catalog_product', 'ship_width', array(
266
+ 'type' => 'decimal',
267
+ 'input' => 'text',
268
+ 'label' => 'Dimension Width',
269
+ 'global' => false,
270
+ 'visible' => 1,
271
+ 'required' => 0,
272
+ 'visible_on_front' => 0,
273
+ 'is_html_allowed_on_front' => 0,
274
+ 'searchable' => 0,
275
+ 'filterable' => 0,
276
+ 'comparable' => 0,
277
+ 'unique' => false,
278
+ 'user_defined' => true,
279
+ 'used_in_product_listing' => false
280
+ ));
281
+
282
+ /* ------ ship_height -------- */
283
+ $this->addAttribute('catalog_product', 'ship_height', array(
284
+ 'type' => 'decimal',
285
+ 'input' => 'text',
286
+ 'label' => 'Dimension Height',
287
+ 'global' => false,
288
+ 'visible' => 1,
289
+ 'required' => 0,
290
+ 'visible_on_front' => 0,
291
+ 'is_html_allowed_on_front' => 0,
292
+ 'searchable' => 0,
293
+ 'filterable' => 0,
294
+ 'comparable' => 0,
295
+ 'unique' => false,
296
+ 'user_defined' => true,
297
+ 'used_in_product_listing' => false
298
+ ));
299
+
300
+ /* ------ shipperhq_poss_boxes -------- */
301
+ $this->addAttribute('catalog_product', 'shipperhq_poss_boxes', array(
302
+ 'type' => 'varchar',
303
+ 'backend' => 'eav/entity_attribute_backend_array',
304
+ 'input' => 'multiselect',
305
+ 'label' => 'Possible Packing Boxes',
306
+ 'global' => false,
307
+ 'visible' => 1,
308
+ 'required' => 0,
309
+ 'visible_on_front' => 0,
310
+ 'is_html_allowed_on_front' => 0,
311
+ 'searchable' => 0,
312
+ 'filterable' => 0,
313
+ 'comparable' => 0,
314
+ 'is_configurable' => 0,
315
+ 'unique' => false,
316
+ 'user_defined' => true,
317
+ 'used_in_product_listing' => false
318
+ ));
319
+
320
+ /* ------ ship_box_tolerance -------- */
321
+ $this->addAttribute('catalog_product', 'ship_box_tolerance', array(
322
+ 'type' => 'int',
323
+ 'input' => 'text',
324
+ 'label' => 'Box Tolerance',
325
+ 'global' => false,
326
+ 'visible' => 1,
327
+ 'required' => 0,
328
+ 'visible_on_front' => 0,
329
+ 'is_html_allowed_on_front' => 0,
330
+ 'searchable' => 0,
331
+ 'filterable' => 0,
332
+ 'comparable' => 0,
333
+ 'unique' => false,
334
+ 'used_in_product_listing' => false,
335
+ 'user_defined' => true,
336
+ 'note' => 'Note: Ignore if unsure'
337
+ ));
338
+
339
+ /*
340
+ *
341
+ *
342
+ *
343
+ */
344
+
345
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
346
+
347
+ $attributeSetArr = $installer->getAllAttributeSetIds($entityTypeId);
348
+
349
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Splitrates')) {
350
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1', 'shipperhq_warehouse' => '10');
351
+ }
352
+ else {
353
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
354
+ }
355
+ $dimAttributeCodes = array('ship_separately' => '2',
356
+ 'shipperhq_dim_group' => '1',
357
+ 'ship_length' => '10',
358
+ 'ship_width' => '11',
359
+ 'ship_height' => '12',
360
+ 'shipperhq_poss_boxes' => '20',
361
+ );
362
+
363
+ foreach ($attributeSetArr as $attributeSetId) {
364
+
365
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
366
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
367
+
368
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
369
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
370
+
371
+ foreach($stdAttributeCodes as $code => $sort) {
372
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
373
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
374
+ }
375
+
376
+ foreach($dimAttributeCodes as $code => $sort) {
377
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
378
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
379
+ }
380
+
381
+ };
382
+
383
+
384
+
385
+ $text = Mage::helper('wsalogger')->getNewVersion() > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : 'text';
386
+
387
+ $isCheckout = array(
388
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
389
+ 'comment' => 'Shipperhq Shipper',
390
+ 'nullable' => 'false',
391
+ 'default' => '0'
392
+ );
393
+
394
+ $carrierType = array(
395
+ 'type' => $text,
396
+ 'comment' => 'Shipperhq Carrier Type',
397
+ 'nullable' => 'true',
398
+ );
399
+
400
+ $dispatchDate = array(
401
+ 'type' => $text,
402
+ 'length' => 20,
403
+ 'comment' => 'Dispatch Date',
404
+ 'nullable' => 'true');
405
+
406
+ $deliveryDate = array(
407
+ 'type' => $text,
408
+ 'length' => 20,
409
+ 'comment' => 'Expected Delivery',
410
+ 'nullable' => 'true');
411
+
412
+ $carrierNotice = array(
413
+ 'type' => $text,
414
+ 'comment' => 'Shipperhq Carrier Notice',
415
+ 'nullable' => 'true',
416
+ );
417
+
418
+ $customDescription = array(
419
+ 'type' => $text,
420
+ 'comment' => 'Shipperhq Custom Description',
421
+ 'nullable' => 'true',
422
+ );
423
+
424
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'is_checkout')){
425
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
426
+ }
427
+
428
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carrier_type')){
429
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
430
+ }
431
+
432
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'dispatch_date')){
433
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
434
+ }
435
+
436
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'delivery_date')){
437
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
438
+ }
439
+
440
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type')){
441
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
442
+ }
443
+
444
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'dispatch_date')){
445
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
446
+ }
447
+
448
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'delivery_date')){
449
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
450
+ }
451
+
452
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice')){
453
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
454
+ }
455
+
456
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'custom_description')){
457
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'custom_description', $customDescription);
458
+ }
459
+
460
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carrier_type')){
461
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
462
+ }
463
+
464
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'dispatch_date')){
465
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
466
+ }
467
+
468
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'delivery_date')){
469
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
470
+ }
471
+
472
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/storage'))) {
473
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/storage'));
474
+
475
+ $table
476
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
477
+ 'primary' => true,
478
+ 'nullable' => false,
479
+ 'unsigned' => true
480
+ ))
481
+ ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '512k', array('nullable' => false))
482
+ ->addForeignKey(
483
+ $this->getFkName('shipperhq_shipper/storage', 'quote_id', 'sales/quote', 'entity_id'),
484
+ 'quote_id',
485
+ $this->getTable('sales/quote'),
486
+ 'entity_id',
487
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
488
+ )
489
+ ;
490
+ $this->getConnection()->createTable($table);
491
+ }
492
+
493
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_packages'))) {
494
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_packages'));
495
+
496
+ $table
497
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
498
+ 'primary' => true,
499
+ 'nullable' => false,
500
+ 'unsigned' => true,
501
+ 'auto_increment' => true
502
+ ))
503
+ ->addColumn('address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
504
+ 'nullable' => false,
505
+ 'unsigned' => true
506
+ ))
507
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
508
+ 'nullable' => false,
509
+ ))
510
+ ->addColumn('carrier_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
511
+ 'nullable' => false,
512
+ ))
513
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
514
+ 'nullable' => false,
515
+ ))
516
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
517
+ 'nullable' => true
518
+ ))
519
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
520
+ 'nullable' => true
521
+ ))
522
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
523
+ 'nullable' => true
524
+ ))
525
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
526
+ 'nullable' => true
527
+ ))
528
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
529
+ 'nullable' => true
530
+ ))
531
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
532
+ 'nullable' => true
533
+ ))
534
+ ->addForeignKey(
535
+ $this->getFkName('shipperhq_shipper/quote_packages', 'address_id', 'sales/quote_address', 'address_id'),
536
+ 'address_id',
537
+ $this->getTable('sales/quote_address'),
538
+ 'address_id',
539
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
540
+ )
541
+ ;
542
+ $this->getConnection()->createTable($table);
543
+ }
544
+
545
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_package_items'))) {
546
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_package_items'));
547
+
548
+ $table
549
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
550
+ 'nullable' => false,
551
+ ))
552
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
553
+ 'nullable' => false,
554
+ ))
555
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
556
+ 'nullable' => true
557
+ ))
558
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
559
+ 'nullable' => true
560
+ ))
561
+ ->addForeignKey(
562
+ $this->getFkName('shipperhq_shipper/quote_package_items', 'package_id', 'shipperhq_shipper/quote_packages', 'package_id'),
563
+ 'package_id',
564
+ $this->getTable('shipperhq_shipper/quote_packages'),
565
+ 'package_id',
566
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
567
+ )
568
+ ;
569
+ $this->getConnection()->createTable($table);
570
+ }
571
+
572
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_packages'))) {
573
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_packages'));
574
+
575
+ $table
576
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
577
+ 'primary' => true,
578
+ 'nullable' => false,
579
+ 'unsigned' => true,
580
+ 'auto_increment' => true
581
+ ))
582
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
583
+ 'nullable' => false,
584
+ 'unsigned' => true
585
+ ))
586
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
587
+ 'nullable' => false,
588
+ ))
589
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
590
+ 'nullable' => false,
591
+ ))
592
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
593
+ 'nullable' => true
594
+ ))
595
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
596
+ 'nullable' => true
597
+ ))
598
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
599
+ 'nullable' => true
600
+ ))
601
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
602
+ 'nullable' => true
603
+ ))
604
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
605
+ 'nullable' => true
606
+ ))
607
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
608
+ 'nullable' => true
609
+ ))
610
+ ->addForeignKey(
611
+ $this->getFkName('shipperhq_shipper/order_packages', 'order_id', 'sales/order', 'entity_id'),
612
+ 'order_id',
613
+ $this->getTable('sales/order'),
614
+ 'entity_id',
615
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
616
+ )
617
+ ;
618
+ $this->getConnection()->createTable($table);
619
+ }
620
+
621
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_package_items'))) {
622
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_package_items'));
623
+
624
+ $table
625
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
626
+ 'nullable' => false,
627
+ 'unsigned' => true,
628
+ ))
629
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
630
+ 'nullable' => false,
631
+ ))
632
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
633
+ 'nullable' => true
634
+ ))
635
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
636
+ 'nullable' => true
637
+ ))
638
+ ->addForeignKey(
639
+ $this->getFkName('shipperhq_shipper/order_package_items', 'package_id', 'shipperhq_shipper/order_packages', 'package_id'),
640
+ 'package_id',
641
+ $this->getTable('shipperhq_shipper/order_packages'),
642
+ 'package_id',
643
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
644
+ )
645
+ ;
646
+ $this->getConnection()->createTable($table);
647
+ }
648
+
649
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.23.php ADDED
@@ -0,0 +1,671 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/attributeupdate'))) {
8
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/attributeupdate'));
9
+
10
+ $table
11
+ ->addColumn('synch_id', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array(
12
+ 'primary' => true,
13
+ 'nullable' => false,
14
+ 'unsigned' => true,
15
+ 'auto_increment' => true
16
+ ))
17
+ ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 0, array(
18
+ 'nullable' => false,
19
+ 'unsigned' => true,
20
+ ))
21
+ ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
22
+ 'nullable' => false,
23
+ ))
24
+ ->addColumn('attribute_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
25
+ 'nullable' => false,
26
+ ))
27
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
28
+ 'nullable' => false,
29
+ ))
30
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
31
+ 'nullable' => false,
32
+ ))
33
+ ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
34
+ 'nullable' => false,
35
+ ))
36
+ ;
37
+ $this->getConnection()->createTable($table);
38
+ }
39
+
40
+ /* ------ shipperhq_shipping_group -------- */
41
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_group', array(
42
+ 'type' => 'varchar',
43
+ 'backend' => 'eav/entity_attribute_backend_array',
44
+ 'input' => 'multiselect',
45
+ 'label' => 'Shipping Group',
46
+ 'global' => false,
47
+ 'visible' => 1,
48
+ 'required' => 0,
49
+ 'visible_on_front' => 0,
50
+ 'is_html_allowed_on_front' => 0,
51
+ 'searchable' => 0,
52
+ 'filterable' => 0,
53
+ 'comparable' => 0,
54
+ 'is_configurable' => 0,
55
+ 'unique' => false,
56
+ 'user_defined' => true,
57
+ 'used_in_product_listing' => false
58
+ ));
59
+
60
+ /* ------ shipperhq_warehouse -------- */
61
+ $this->addAttribute('catalog_product', 'shipperhq_warehouse', array(
62
+ 'type' => 'text',
63
+ 'backend' => 'eav/entity_attribute_backend_array',
64
+ 'input' => 'multiselect',
65
+ 'label' => 'Origin',
66
+ 'global' => false,
67
+ 'visible' => 1,
68
+ 'required' => 0,
69
+ 'visible_on_front' => 0,
70
+ 'is_html_allowed_on_front' => 0,
71
+ 'searchable' => 0,
72
+ 'filterable' => 0,
73
+ 'comparable' => 0,
74
+ 'is_configurable' => 0,
75
+ 'unique' => false,
76
+ 'user_defined' => true,
77
+ 'used_in_product_listing' => false
78
+ ));
79
+
80
+ /* ------ shipperhq_shipping_qty -------- */
81
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_qty', array(
82
+ 'type' => 'int',
83
+ 'input' => 'text',
84
+ 'label' => 'Shipping Qty',
85
+ 'global' => false,
86
+ 'visible' => 1,
87
+ 'required' => 0,
88
+ 'visible_on_front' => 0,
89
+ 'is_html_allowed_on_front' => 0,
90
+ 'searchable' => 0,
91
+ 'filterable' => 0,
92
+ 'comparable' => 0,
93
+ 'unique' => false,
94
+ 'user_defined' => true,
95
+ 'used_in_product_listing' => false
96
+ ));
97
+
98
+ /* ------ shipperhq_shipping_fee -------- */
99
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_fee', array(
100
+ 'type' => 'decimal',
101
+ 'input' => 'price',
102
+ 'label' => 'Shipping Fee',
103
+ 'global' => false,
104
+ 'visible' => 1,
105
+ 'required' => 0,
106
+ 'visible_on_front' => 0,
107
+ 'is_html_allowed_on_front' => 0,
108
+ 'searchable' => 0,
109
+ 'filterable' => 0,
110
+ 'comparable' => 0,
111
+ 'unique' => false,
112
+ 'user_defined' => true,
113
+ 'used_in_product_listing' => false
114
+ ));
115
+
116
+ /* ------ shipperhq_additional_price -------- */
117
+ $this->addAttribute('catalog_product', 'shipperhq_additional_price', array(
118
+ 'type' => 'decimal',
119
+ 'input' => 'price',
120
+ 'label' => 'Additional Price',
121
+ 'global' => false,
122
+ 'visible' => 1,
123
+ 'required' => 0,
124
+ 'visible_on_front' => 0,
125
+ 'is_html_allowed_on_front' => 0,
126
+ 'searchable' => 0,
127
+ 'filterable' => 0,
128
+ 'comparable' => 0,
129
+ 'unique' => false,
130
+ 'user_defined' => true,
131
+ 'used_in_product_listing' => false
132
+ ));
133
+
134
+ /* ------ shipperhq_handling_fee -------- */
135
+ $this->addAttribute('catalog_product', 'shipperhq_handling_fee', array(
136
+ 'type' => 'decimal',
137
+ 'input' => 'price',
138
+ 'label' => 'Handling Fee',
139
+ 'global' => false,
140
+ 'visible' => 1,
141
+ 'required' => 0,
142
+ 'visible_on_front' => 0,
143
+ 'is_html_allowed_on_front' => 0,
144
+ 'searchable' => 0,
145
+ 'filterable' => 0,
146
+ 'comparable' => 0,
147
+ 'unique' => false,
148
+ 'user_defined' => true,
149
+ 'used_in_product_listing' => false
150
+ ));
151
+
152
+ /* ------ shipperhq_carrier_code -------- */
153
+ $this->addAttribute('catalog_product', 'shipperhq_carrier_code', array(
154
+ 'type' => 'text',
155
+ 'input' => 'text',
156
+ 'label' => 'Carrier Code',
157
+ 'global' => false,
158
+ 'visible' => 1,
159
+ 'required' => 0,
160
+ 'visible_on_front' => 0,
161
+ 'is_html_allowed_on_front' => 0,
162
+ 'searchable' => 0,
163
+ 'filterable' => 0,
164
+ 'comparable' => 0,
165
+ 'unique' => false,
166
+ 'user_defined' => true,
167
+ 'used_in_product_listing' => false
168
+ ));
169
+
170
+ /* ------ shipperhq_volume_weight -------- */
171
+ $this->addAttribute('catalog_product', 'shipperhq_volume_weight', array(
172
+ 'type' => 'decimal',
173
+ 'input' => 'text',
174
+ 'label' => 'Volume Weight',
175
+ 'global' => false,
176
+ 'visible' => 1,
177
+ 'required' => 0,
178
+ 'visible_on_front' => 0,
179
+ 'is_html_allowed_on_front' => 0,
180
+ 'searchable' => 0,
181
+ 'filterable' => 0,
182
+ 'comparable' => 0,
183
+ 'unique' => false,
184
+ 'user_defined' => true,
185
+ 'used_in_product_listing' => false,
186
+ 'note' => 'This value is only used in conjunction with shipping filters'
187
+ ));
188
+
189
+ /* ------ shipperhq_declared_value -------- */
190
+ $this->addAttribute('catalog_product', 'shipperhq_declared_value', array(
191
+ 'type' => 'decimal',
192
+ 'input' => 'price',
193
+ 'label' => 'Declared Value',
194
+ 'global' => false,
195
+ 'visible' => 1,
196
+ 'required' => 0,
197
+ 'visible_on_front' => 0,
198
+ 'is_html_allowed_on_front' => 0,
199
+ 'searchable' => 0,
200
+ 'filterable' => 0,
201
+ 'comparable' => 0,
202
+ 'unique' => false,
203
+ 'user_defined' => true,
204
+ 'used_in_product_listing' => false,
205
+ 'note' => 'The deemed cost of this product for customs & insurance purposes'
206
+ ));
207
+
208
+ /* ------ ship_separately -------- */
209
+ $this->addAttribute('catalog_product', 'ship_separately', array(
210
+ 'type' => 'int',
211
+ 'input' => 'boolean',
212
+ 'label' => 'Ship Separately',
213
+ 'global' => false,
214
+ 'visible' => 1,
215
+ 'required' => 0,
216
+ 'visible_on_front' => 0,
217
+ 'is_html_allowed_on_front' => 0,
218
+ 'searchable' => 0,
219
+ 'filterable' => 0,
220
+ 'comparable' => 0,
221
+ 'unique' => false,
222
+ 'user_defined' => true,
223
+ 'used_in_product_listing' => false
224
+ ));
225
+
226
+ /* ------ shipperhq_dim_group -------- */
227
+ $this->addAttribute('catalog_product', 'shipperhq_dim_group', array(
228
+ 'type' => 'varchar',
229
+ 'input' => 'select',
230
+ 'label' => 'ShipperHQ Dimensional Rule Group',
231
+ 'backend' => 'eav/entity_attribute_backend_array',
232
+ 'global' => false,
233
+ 'visible' => 1,
234
+ 'required' => 0,
235
+ 'visible_on_front' => 0,
236
+ 'is_html_allowed_on_front' => 0,
237
+ 'searchable' => 0,
238
+ 'filterable' => 0,
239
+ 'comparable' => 0,
240
+ 'is_configurable' => 0,
241
+ 'unique' => false,
242
+ 'user_defined' => true,
243
+ 'used_in_product_listing' => false
244
+ ));
245
+
246
+ /* ------ ship_length -------- */
247
+ $this->addAttribute('catalog_product', 'ship_length', array(
248
+ 'type' => 'decimal',
249
+ 'input' => 'text',
250
+ 'label' => 'Dimension Length',
251
+ 'global' => false,
252
+ 'visible' => 1,
253
+ 'required' => 0,
254
+ 'visible_on_front' => 0,
255
+ 'is_html_allowed_on_front' => 0,
256
+ 'searchable' => 0,
257
+ 'filterable' => 0,
258
+ 'comparable' => 0,
259
+ 'unique' => false,
260
+ 'user_defined' => true,
261
+ 'used_in_product_listing' => false
262
+ ));
263
+
264
+ /* ------ ship_width -------- */
265
+ $this->addAttribute('catalog_product', 'ship_width', array(
266
+ 'type' => 'decimal',
267
+ 'input' => 'text',
268
+ 'label' => 'Dimension Width',
269
+ 'global' => false,
270
+ 'visible' => 1,
271
+ 'required' => 0,
272
+ 'visible_on_front' => 0,
273
+ 'is_html_allowed_on_front' => 0,
274
+ 'searchable' => 0,
275
+ 'filterable' => 0,
276
+ 'comparable' => 0,
277
+ 'unique' => false,
278
+ 'user_defined' => true,
279
+ 'used_in_product_listing' => false
280
+ ));
281
+
282
+ /* ------ ship_height -------- */
283
+ $this->addAttribute('catalog_product', 'ship_height', array(
284
+ 'type' => 'decimal',
285
+ 'input' => 'text',
286
+ 'label' => 'Dimension Height',
287
+ 'global' => false,
288
+ 'visible' => 1,
289
+ 'required' => 0,
290
+ 'visible_on_front' => 0,
291
+ 'is_html_allowed_on_front' => 0,
292
+ 'searchable' => 0,
293
+ 'filterable' => 0,
294
+ 'comparable' => 0,
295
+ 'unique' => false,
296
+ 'user_defined' => true,
297
+ 'used_in_product_listing' => false
298
+ ));
299
+
300
+ /* ------ shipperhq_poss_boxes -------- */
301
+ $this->addAttribute('catalog_product', 'shipperhq_poss_boxes', array(
302
+ 'type' => 'varchar',
303
+ 'backend' => 'eav/entity_attribute_backend_array',
304
+ 'input' => 'multiselect',
305
+ 'label' => 'Possible Packing Boxes',
306
+ 'global' => false,
307
+ 'visible' => 1,
308
+ 'required' => 0,
309
+ 'visible_on_front' => 0,
310
+ 'is_html_allowed_on_front' => 0,
311
+ 'searchable' => 0,
312
+ 'filterable' => 0,
313
+ 'comparable' => 0,
314
+ 'is_configurable' => 0,
315
+ 'unique' => false,
316
+ 'user_defined' => true,
317
+ 'used_in_product_listing' => false
318
+ ));
319
+
320
+ /* ------ ship_box_tolerance -------- */
321
+ $this->addAttribute('catalog_product', 'ship_box_tolerance', array(
322
+ 'type' => 'int',
323
+ 'input' => 'text',
324
+ 'label' => 'Box Tolerance',
325
+ 'global' => false,
326
+ 'visible' => 1,
327
+ 'required' => 0,
328
+ 'visible_on_front' => 0,
329
+ 'is_html_allowed_on_front' => 0,
330
+ 'searchable' => 0,
331
+ 'filterable' => 0,
332
+ 'comparable' => 0,
333
+ 'unique' => false,
334
+ 'used_in_product_listing' => false,
335
+ 'user_defined' => true,
336
+ 'note' => 'Note: Ignore if unsure'
337
+ ));
338
+
339
+ /*
340
+ *
341
+ *
342
+ *
343
+ */
344
+
345
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
346
+
347
+ $attributeSetArr = $installer->getAllAttributeSetIds($entityTypeId);
348
+
349
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Splitrates')) {
350
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1', 'shipperhq_warehouse' => '10');
351
+ }
352
+ else {
353
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
354
+ }
355
+ $dimAttributeCodes = array('ship_separately' => '2',
356
+ 'shipperhq_dim_group' => '1',
357
+ 'ship_length' => '10',
358
+ 'ship_width' => '11',
359
+ 'ship_height' => '12',
360
+ 'shipperhq_poss_boxes' => '20',
361
+ );
362
+
363
+ foreach ($attributeSetArr as $attributeSetId) {
364
+
365
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
366
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
367
+
368
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
369
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
370
+
371
+ foreach($stdAttributeCodes as $code => $sort) {
372
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
373
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
374
+ }
375
+
376
+ foreach($dimAttributeCodes as $code => $sort) {
377
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
378
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
379
+ }
380
+
381
+ };
382
+
383
+
384
+
385
+ $text = Mage::helper('wsalogger')->getNewVersion() > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : 'text';
386
+
387
+ $isCheckout = array(
388
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
389
+ 'comment' => 'Shipperhq Shipper',
390
+ 'nullable' => 'false',
391
+ 'default' => '0'
392
+ );
393
+
394
+ $carrierType = array(
395
+ 'type' => $text,
396
+ 'comment' => 'Shipperhq Carrier Type',
397
+ 'nullable' => 'true',
398
+ );
399
+
400
+ $dispatchDate = array(
401
+ 'type' => $text,
402
+ 'length' => 20,
403
+ 'comment' => 'Dispatch Date',
404
+ 'nullable' => 'true');
405
+
406
+ $deliveryDate = array(
407
+ 'type' => $text,
408
+ 'length' => 20,
409
+ 'comment' => 'Expected Delivery',
410
+ 'nullable' => 'true');
411
+
412
+ $carrierNotice = array(
413
+ 'type' => $text,
414
+ 'comment' => 'Shipperhq Carrier Notice',
415
+ 'nullable' => 'true',
416
+ );
417
+
418
+ $customDescription = array(
419
+ 'type' => $text,
420
+ 'comment' => 'Shipperhq Custom Description',
421
+ 'nullable' => 'true',
422
+ );
423
+
424
+ $carrierId = array(
425
+ 'type' => $text,
426
+ 'length' => 20,
427
+ 'comment' => 'Shipperhq Carrier ID',
428
+ 'nullable' => 'true',
429
+ );
430
+
431
+ $customDuties = array(
432
+ 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
433
+ 'scale' => 4,
434
+ 'precision' => 12,
435
+ 'comment' => 'Shipperhq Custom Duties',
436
+ );
437
+
438
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'is_checkout')){
439
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
440
+ }
441
+
442
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carrier_type')){
443
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
444
+ }
445
+
446
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'dispatch_date')){
447
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
448
+ }
449
+
450
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'delivery_date')){
451
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
452
+ }
453
+
454
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type')){
455
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
456
+ }
457
+
458
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'dispatch_date')){
459
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
460
+ }
461
+
462
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'delivery_date')){
463
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
464
+ }
465
+
466
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice')){
467
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
468
+ }
469
+
470
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'custom_description')){
471
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'custom_description', $customDescription);
472
+ }
473
+
474
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_id')){
475
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_id', $carrierId);
476
+ }
477
+
478
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'custom_duties')){
479
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'custom_duties', $customDuties);
480
+ }
481
+
482
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carrier_type')){
483
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
484
+ }
485
+
486
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'dispatch_date')){
487
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
488
+ }
489
+
490
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'delivery_date')){
491
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
492
+ }
493
+
494
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/storage'))) {
495
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/storage'));
496
+
497
+ $table
498
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
499
+ 'primary' => true,
500
+ 'nullable' => false,
501
+ 'unsigned' => true
502
+ ))
503
+ ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '512k', array('nullable' => false))
504
+ ->addForeignKey(
505
+ $this->getFkName('shipperhq_shipper/storage', 'quote_id', 'sales/quote', 'entity_id'),
506
+ 'quote_id',
507
+ $this->getTable('sales/quote'),
508
+ 'entity_id',
509
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
510
+ )
511
+ ;
512
+ $this->getConnection()->createTable($table);
513
+ }
514
+
515
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_packages'))) {
516
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_packages'));
517
+
518
+ $table
519
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
520
+ 'primary' => true,
521
+ 'nullable' => false,
522
+ 'unsigned' => true,
523
+ 'auto_increment' => true
524
+ ))
525
+ ->addColumn('address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
526
+ 'nullable' => false,
527
+ 'unsigned' => true
528
+ ))
529
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
530
+ 'nullable' => false,
531
+ ))
532
+ ->addColumn('carrier_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
533
+ 'nullable' => false,
534
+ ))
535
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
536
+ 'nullable' => false,
537
+ ))
538
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
539
+ 'nullable' => true
540
+ ))
541
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
542
+ 'nullable' => true
543
+ ))
544
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
545
+ 'nullable' => true
546
+ ))
547
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
548
+ 'nullable' => true
549
+ ))
550
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
551
+ 'nullable' => true
552
+ ))
553
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
554
+ 'nullable' => true
555
+ ))
556
+ ->addForeignKey(
557
+ $this->getFkName('shipperhq_shipper/quote_packages', 'address_id', 'sales/quote_address', 'address_id'),
558
+ 'address_id',
559
+ $this->getTable('sales/quote_address'),
560
+ 'address_id',
561
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
562
+ )
563
+ ;
564
+ $this->getConnection()->createTable($table);
565
+ }
566
+
567
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_package_items'))) {
568
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_package_items'));
569
+
570
+ $table
571
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
572
+ 'nullable' => false,
573
+ ))
574
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
575
+ 'nullable' => false,
576
+ ))
577
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
578
+ 'nullable' => true
579
+ ))
580
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
581
+ 'nullable' => true
582
+ ))
583
+ ->addForeignKey(
584
+ $this->getFkName('shipperhq_shipper/quote_package_items', 'package_id', 'shipperhq_shipper/quote_packages', 'package_id'),
585
+ 'package_id',
586
+ $this->getTable('shipperhq_shipper/quote_packages'),
587
+ 'package_id',
588
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
589
+ )
590
+ ;
591
+ $this->getConnection()->createTable($table);
592
+ }
593
+
594
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_packages'))) {
595
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_packages'));
596
+
597
+ $table
598
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
599
+ 'primary' => true,
600
+ 'nullable' => false,
601
+ 'unsigned' => true,
602
+ 'auto_increment' => true
603
+ ))
604
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
605
+ 'nullable' => false,
606
+ 'unsigned' => true
607
+ ))
608
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
609
+ 'nullable' => false,
610
+ ))
611
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
612
+ 'nullable' => false,
613
+ ))
614
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
615
+ 'nullable' => true
616
+ ))
617
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
618
+ 'nullable' => true
619
+ ))
620
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
621
+ 'nullable' => true
622
+ ))
623
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
624
+ 'nullable' => true
625
+ ))
626
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
627
+ 'nullable' => true
628
+ ))
629
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
630
+ 'nullable' => true
631
+ ))
632
+ ->addForeignKey(
633
+ $this->getFkName('shipperhq_shipper/order_packages', 'order_id', 'sales/order', 'entity_id'),
634
+ 'order_id',
635
+ $this->getTable('sales/order'),
636
+ 'entity_id',
637
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
638
+ )
639
+ ;
640
+ $this->getConnection()->createTable($table);
641
+ }
642
+
643
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_package_items'))) {
644
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_package_items'));
645
+
646
+ $table
647
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
648
+ 'nullable' => false,
649
+ 'unsigned' => true,
650
+ ))
651
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
652
+ 'nullable' => false,
653
+ ))
654
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
655
+ 'nullable' => true
656
+ ))
657
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
658
+ 'nullable' => true
659
+ ))
660
+ ->addForeignKey(
661
+ $this->getFkName('shipperhq_shipper/order_package_items', 'package_id', 'shipperhq_shipper/order_packages', 'package_id'),
662
+ 'package_id',
663
+ $this->getTable('shipperhq_shipper/order_packages'),
664
+ 'package_id',
665
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
666
+ )
667
+ ;
668
+ $this->getConnection()->createTable($table);
669
+ }
670
+
671
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.24.php ADDED
@@ -0,0 +1,690 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/attributeupdate'))) {
8
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/attributeupdate'));
9
+
10
+ $table
11
+ ->addColumn('synch_id', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array(
12
+ 'primary' => true,
13
+ 'nullable' => false,
14
+ 'unsigned' => true,
15
+ 'auto_increment' => true
16
+ ))
17
+ ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 0, array(
18
+ 'nullable' => false,
19
+ 'unsigned' => true,
20
+ ))
21
+ ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
22
+ 'nullable' => false,
23
+ ))
24
+ ->addColumn('attribute_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
25
+ 'nullable' => false,
26
+ ))
27
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
28
+ 'nullable' => false,
29
+ ))
30
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
31
+ 'nullable' => false,
32
+ ))
33
+ ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
34
+ 'nullable' => false,
35
+ ))
36
+ ;
37
+ $this->getConnection()->createTable($table);
38
+ }
39
+
40
+ /* ------ shipperhq_shipping_group -------- */
41
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_group', array(
42
+ 'type' => 'varchar',
43
+ 'backend' => 'eav/entity_attribute_backend_array',
44
+ 'input' => 'multiselect',
45
+ 'label' => 'Shipping Group',
46
+ 'global' => false,
47
+ 'visible' => 1,
48
+ 'required' => 0,
49
+ 'visible_on_front' => 0,
50
+ 'is_html_allowed_on_front' => 0,
51
+ 'searchable' => 0,
52
+ 'filterable' => 0,
53
+ 'comparable' => 0,
54
+ 'is_configurable' => 0,
55
+ 'unique' => false,
56
+ 'user_defined' => true,
57
+ 'used_in_product_listing' => false
58
+ ));
59
+
60
+ /* ------ shipperhq_warehouse -------- */
61
+ $this->addAttribute('catalog_product', 'shipperhq_warehouse', array(
62
+ 'type' => 'text',
63
+ 'backend' => 'eav/entity_attribute_backend_array',
64
+ 'input' => 'multiselect',
65
+ 'label' => 'Origin',
66
+ 'global' => false,
67
+ 'visible' => 1,
68
+ 'required' => 0,
69
+ 'visible_on_front' => 0,
70
+ 'is_html_allowed_on_front' => 0,
71
+ 'searchable' => 0,
72
+ 'filterable' => 0,
73
+ 'comparable' => 0,
74
+ 'is_configurable' => 0,
75
+ 'unique' => false,
76
+ 'user_defined' => true,
77
+ 'used_in_product_listing' => false
78
+ ));
79
+
80
+ /* ------ shipperhq_shipping_qty -------- */
81
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_qty', array(
82
+ 'type' => 'int',
83
+ 'input' => 'text',
84
+ 'label' => 'Shipping Qty',
85
+ 'global' => false,
86
+ 'visible' => 1,
87
+ 'required' => 0,
88
+ 'visible_on_front' => 0,
89
+ 'is_html_allowed_on_front' => 0,
90
+ 'searchable' => 0,
91
+ 'filterable' => 0,
92
+ 'comparable' => 0,
93
+ 'unique' => false,
94
+ 'user_defined' => true,
95
+ 'used_in_product_listing' => false
96
+ ));
97
+
98
+ /* ------ shipperhq_shipping_fee -------- */
99
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_fee', array(
100
+ 'type' => 'decimal',
101
+ 'input' => 'price',
102
+ 'label' => 'Shipping Fee',
103
+ 'global' => false,
104
+ 'visible' => 1,
105
+ 'required' => 0,
106
+ 'visible_on_front' => 0,
107
+ 'is_html_allowed_on_front' => 0,
108
+ 'searchable' => 0,
109
+ 'filterable' => 0,
110
+ 'comparable' => 0,
111
+ 'unique' => false,
112
+ 'user_defined' => true,
113
+ 'used_in_product_listing' => false
114
+ ));
115
+
116
+ /* ------ shipperhq_additional_price -------- */
117
+ $this->addAttribute('catalog_product', 'shipperhq_additional_price', array(
118
+ 'type' => 'decimal',
119
+ 'input' => 'price',
120
+ 'label' => 'Additional Price',
121
+ 'global' => false,
122
+ 'visible' => 1,
123
+ 'required' => 0,
124
+ 'visible_on_front' => 0,
125
+ 'is_html_allowed_on_front' => 0,
126
+ 'searchable' => 0,
127
+ 'filterable' => 0,
128
+ 'comparable' => 0,
129
+ 'unique' => false,
130
+ 'user_defined' => true,
131
+ 'used_in_product_listing' => false
132
+ ));
133
+
134
+ /* ------ shipperhq_handling_fee -------- */
135
+ $this->addAttribute('catalog_product', 'shipperhq_handling_fee', array(
136
+ 'type' => 'decimal',
137
+ 'input' => 'price',
138
+ 'label' => 'Handling Fee',
139
+ 'global' => false,
140
+ 'visible' => 1,
141
+ 'required' => 0,
142
+ 'visible_on_front' => 0,
143
+ 'is_html_allowed_on_front' => 0,
144
+ 'searchable' => 0,
145
+ 'filterable' => 0,
146
+ 'comparable' => 0,
147
+ 'unique' => false,
148
+ 'user_defined' => true,
149
+ 'used_in_product_listing' => false
150
+ ));
151
+
152
+ /* ------ shipperhq_carrier_code -------- */
153
+ $this->addAttribute('catalog_product', 'shipperhq_carrier_code', array(
154
+ 'type' => 'text',
155
+ 'input' => 'text',
156
+ 'label' => 'Carrier Code',
157
+ 'global' => false,
158
+ 'visible' => 1,
159
+ 'required' => 0,
160
+ 'visible_on_front' => 0,
161
+ 'is_html_allowed_on_front' => 0,
162
+ 'searchable' => 0,
163
+ 'filterable' => 0,
164
+ 'comparable' => 0,
165
+ 'unique' => false,
166
+ 'user_defined' => true,
167
+ 'used_in_product_listing' => false
168
+ ));
169
+
170
+ /* ------ shipperhq_volume_weight -------- */
171
+ $this->addAttribute('catalog_product', 'shipperhq_volume_weight', array(
172
+ 'type' => 'decimal',
173
+ 'input' => 'text',
174
+ 'label' => 'Volume Weight',
175
+ 'global' => false,
176
+ 'visible' => 1,
177
+ 'required' => 0,
178
+ 'visible_on_front' => 0,
179
+ 'is_html_allowed_on_front' => 0,
180
+ 'searchable' => 0,
181
+ 'filterable' => 0,
182
+ 'comparable' => 0,
183
+ 'unique' => false,
184
+ 'user_defined' => true,
185
+ 'used_in_product_listing' => false,
186
+ 'note' => 'This value is only used in conjunction with shipping filters'
187
+ ));
188
+
189
+ /* ------ shipperhq_declared_value -------- */
190
+ $this->addAttribute('catalog_product', 'shipperhq_declared_value', array(
191
+ 'type' => 'decimal',
192
+ 'input' => 'price',
193
+ 'label' => 'Declared Value',
194
+ 'global' => false,
195
+ 'visible' => 1,
196
+ 'required' => 0,
197
+ 'visible_on_front' => 0,
198
+ 'is_html_allowed_on_front' => 0,
199
+ 'searchable' => 0,
200
+ 'filterable' => 0,
201
+ 'comparable' => 0,
202
+ 'unique' => false,
203
+ 'user_defined' => true,
204
+ 'used_in_product_listing' => false,
205
+ 'note' => 'The deemed cost of this product for customs & insurance purposes'
206
+ ));
207
+
208
+ /* ------ ship_separately -------- */
209
+ $this->addAttribute('catalog_product', 'ship_separately', array(
210
+ 'type' => 'int',
211
+ 'input' => 'boolean',
212
+ 'label' => 'Ship Separately',
213
+ 'global' => false,
214
+ 'visible' => 1,
215
+ 'required' => 0,
216
+ 'visible_on_front' => 0,
217
+ 'is_html_allowed_on_front' => 0,
218
+ 'searchable' => 0,
219
+ 'filterable' => 0,
220
+ 'comparable' => 0,
221
+ 'unique' => false,
222
+ 'user_defined' => true,
223
+ 'used_in_product_listing' => false
224
+ ));
225
+
226
+ /* ------ shipperhq_dim_group -------- */
227
+ $this->addAttribute('catalog_product', 'shipperhq_dim_group', array(
228
+ 'type' => 'varchar',
229
+ 'input' => 'select',
230
+ 'label' => 'ShipperHQ Dimensional Rule Group',
231
+ 'backend' => 'eav/entity_attribute_backend_array',
232
+ 'global' => false,
233
+ 'visible' => 1,
234
+ 'required' => 0,
235
+ 'visible_on_front' => 0,
236
+ 'is_html_allowed_on_front' => 0,
237
+ 'searchable' => 0,
238
+ 'filterable' => 0,
239
+ 'comparable' => 0,
240
+ 'is_configurable' => 0,
241
+ 'unique' => false,
242
+ 'user_defined' => true,
243
+ 'used_in_product_listing' => false
244
+ ));
245
+
246
+ /* ------ ship_length -------- */
247
+ $this->addAttribute('catalog_product', 'ship_length', array(
248
+ 'type' => 'decimal',
249
+ 'input' => 'text',
250
+ 'label' => 'Dimension Length',
251
+ 'global' => false,
252
+ 'visible' => 1,
253
+ 'required' => 0,
254
+ 'visible_on_front' => 0,
255
+ 'is_html_allowed_on_front' => 0,
256
+ 'searchable' => 0,
257
+ 'filterable' => 0,
258
+ 'comparable' => 0,
259
+ 'unique' => false,
260
+ 'user_defined' => true,
261
+ 'used_in_product_listing' => false
262
+ ));
263
+
264
+ /* ------ ship_width -------- */
265
+ $this->addAttribute('catalog_product', 'ship_width', array(
266
+ 'type' => 'decimal',
267
+ 'input' => 'text',
268
+ 'label' => 'Dimension Width',
269
+ 'global' => false,
270
+ 'visible' => 1,
271
+ 'required' => 0,
272
+ 'visible_on_front' => 0,
273
+ 'is_html_allowed_on_front' => 0,
274
+ 'searchable' => 0,
275
+ 'filterable' => 0,
276
+ 'comparable' => 0,
277
+ 'unique' => false,
278
+ 'user_defined' => true,
279
+ 'used_in_product_listing' => false
280
+ ));
281
+
282
+ /* ------ ship_height -------- */
283
+ $this->addAttribute('catalog_product', 'ship_height', array(
284
+ 'type' => 'decimal',
285
+ 'input' => 'text',
286
+ 'label' => 'Dimension Height',
287
+ 'global' => false,
288
+ 'visible' => 1,
289
+ 'required' => 0,
290
+ 'visible_on_front' => 0,
291
+ 'is_html_allowed_on_front' => 0,
292
+ 'searchable' => 0,
293
+ 'filterable' => 0,
294
+ 'comparable' => 0,
295
+ 'unique' => false,
296
+ 'user_defined' => true,
297
+ 'used_in_product_listing' => false
298
+ ));
299
+
300
+ /* ------ shipperhq_poss_boxes -------- */
301
+ $this->addAttribute('catalog_product', 'shipperhq_poss_boxes', array(
302
+ 'type' => 'varchar',
303
+ 'backend' => 'eav/entity_attribute_backend_array',
304
+ 'input' => 'multiselect',
305
+ 'label' => 'Possible Packing Boxes',
306
+ 'global' => false,
307
+ 'visible' => 1,
308
+ 'required' => 0,
309
+ 'visible_on_front' => 0,
310
+ 'is_html_allowed_on_front' => 0,
311
+ 'searchable' => 0,
312
+ 'filterable' => 0,
313
+ 'comparable' => 0,
314
+ 'is_configurable' => 0,
315
+ 'unique' => false,
316
+ 'user_defined' => true,
317
+ 'used_in_product_listing' => false
318
+ ));
319
+
320
+ /* ------ ship_box_tolerance -------- */
321
+ $this->addAttribute('catalog_product', 'ship_box_tolerance', array(
322
+ 'type' => 'int',
323
+ 'input' => 'text',
324
+ 'label' => 'Box Tolerance',
325
+ 'global' => false,
326
+ 'visible' => 1,
327
+ 'required' => 0,
328
+ 'visible_on_front' => 0,
329
+ 'is_html_allowed_on_front' => 0,
330
+ 'searchable' => 0,
331
+ 'filterable' => 0,
332
+ 'comparable' => 0,
333
+ 'unique' => false,
334
+ 'used_in_product_listing' => false,
335
+ 'user_defined' => true,
336
+ 'note' => 'Note: Ignore if unsure'
337
+ ));
338
+
339
+ /*
340
+ *
341
+ *
342
+ *
343
+ */
344
+
345
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
346
+
347
+ $attributeSetArr = $installer->getAllAttributeSetIds($entityTypeId);
348
+
349
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Splitrates')) {
350
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1', 'shipperhq_warehouse' => '10');
351
+ }
352
+ else {
353
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
354
+ }
355
+ $dimAttributeCodes = array('ship_separately' => '2',
356
+ 'shipperhq_dim_group' => '1',
357
+ 'ship_length' => '10',
358
+ 'ship_width' => '11',
359
+ 'ship_height' => '12',
360
+ 'shipperhq_poss_boxes' => '20',
361
+ );
362
+
363
+ foreach ($attributeSetArr as $attributeSetId) {
364
+
365
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
366
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
367
+
368
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
369
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
370
+
371
+ foreach($stdAttributeCodes as $code => $sort) {
372
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
373
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
374
+ }
375
+
376
+ foreach($dimAttributeCodes as $code => $sort) {
377
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
378
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
379
+ }
380
+
381
+ };
382
+
383
+
384
+
385
+ $text = Mage::helper('wsalogger')->getNewVersion() > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : 'text';
386
+
387
+ $isCheckout = array(
388
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
389
+ 'comment' => 'Shipperhq Shipper',
390
+ 'nullable' => 'false',
391
+ 'default' => '0'
392
+ );
393
+
394
+ $carrierType = array(
395
+ 'type' => $text,
396
+ 'comment' => 'Shipperhq Carrier Type',
397
+ 'nullable' => 'true',
398
+ );
399
+
400
+ $dispatchDate = array(
401
+ 'type' => $text,
402
+ 'length' => 20,
403
+ 'comment' => 'Dispatch Date',
404
+ 'nullable' => 'true');
405
+
406
+ $deliveryDate = array(
407
+ 'type' => $text,
408
+ 'length' => 20,
409
+ 'comment' => 'Expected Delivery',
410
+ 'nullable' => 'true');
411
+
412
+ $carrierNotice = array(
413
+ 'type' => $text,
414
+ 'comment' => 'Shipperhq Carrier Notice',
415
+ 'nullable' => 'true',
416
+ );
417
+
418
+ $customDescription = array(
419
+ 'type' => $text,
420
+ 'comment' => 'Shipperhq Custom Description',
421
+ 'nullable' => 'true',
422
+ );
423
+
424
+ $carrierId = array(
425
+ 'type' => $text,
426
+ 'length' => 20,
427
+ 'comment' => 'Shipperhq Carrier ID',
428
+ 'nullable' => 'true',
429
+ );
430
+
431
+ $customDuties = array(
432
+ 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
433
+ 'scale' => 4,
434
+ 'precision' => 12,
435
+ 'comment' => 'Shipperhq Custom Duties',
436
+ );
437
+
438
+ $confirmationNo = array(
439
+ 'type' => $text,
440
+ 'length' => 20,
441
+ 'comment' => 'Shipperhq Confirmation Number',
442
+ 'nullable' => 'true',
443
+ );
444
+
445
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'is_checkout')){
446
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
447
+ }
448
+
449
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carrier_type')){
450
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
451
+ }
452
+
453
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'dispatch_date')){
454
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
455
+ }
456
+
457
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'delivery_date')){
458
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
459
+ }
460
+
461
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type')){
462
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
463
+ }
464
+
465
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'dispatch_date')){
466
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
467
+ }
468
+
469
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'delivery_date')){
470
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
471
+ }
472
+
473
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice')){
474
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
475
+ }
476
+
477
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'custom_description')){
478
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'custom_description', $customDescription);
479
+ }
480
+
481
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_id')){
482
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_id', $carrierId);
483
+ }
484
+
485
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carrier_id')){
486
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'carrier_id', $carrierId );
487
+ }
488
+
489
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carrier_id')){
490
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_id', $carrierId );
491
+ }
492
+
493
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'confirmation_number')){
494
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'confirmation_number', $confirmationNo );
495
+ }
496
+
497
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'custom_duties')){
498
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'custom_duties', $customDuties);
499
+ }
500
+
501
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carrier_type')){
502
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
503
+ }
504
+
505
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'dispatch_date')){
506
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
507
+ }
508
+
509
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'delivery_date')){
510
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
511
+ }
512
+
513
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/storage'))) {
514
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/storage'));
515
+
516
+ $table
517
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
518
+ 'primary' => true,
519
+ 'nullable' => false,
520
+ 'unsigned' => true
521
+ ))
522
+ ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '512k', array('nullable' => false))
523
+ ->addForeignKey(
524
+ $this->getFkName('shipperhq_shipper/storage', 'quote_id', 'sales/quote', 'entity_id'),
525
+ 'quote_id',
526
+ $this->getTable('sales/quote'),
527
+ 'entity_id',
528
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
529
+ )
530
+ ;
531
+ $this->getConnection()->createTable($table);
532
+ }
533
+
534
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_packages'))) {
535
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_packages'));
536
+
537
+ $table
538
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
539
+ 'primary' => true,
540
+ 'nullable' => false,
541
+ 'unsigned' => true,
542
+ 'auto_increment' => true
543
+ ))
544
+ ->addColumn('address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
545
+ 'nullable' => false,
546
+ 'unsigned' => true
547
+ ))
548
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
549
+ 'nullable' => false,
550
+ ))
551
+ ->addColumn('carrier_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
552
+ 'nullable' => false,
553
+ ))
554
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
555
+ 'nullable' => false,
556
+ ))
557
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
558
+ 'nullable' => true
559
+ ))
560
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
561
+ 'nullable' => true
562
+ ))
563
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
564
+ 'nullable' => true
565
+ ))
566
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
567
+ 'nullable' => true
568
+ ))
569
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
570
+ 'nullable' => true
571
+ ))
572
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
573
+ 'nullable' => true
574
+ ))
575
+ ->addForeignKey(
576
+ $this->getFkName('shipperhq_shipper/quote_packages', 'address_id', 'sales/quote_address', 'address_id'),
577
+ 'address_id',
578
+ $this->getTable('sales/quote_address'),
579
+ 'address_id',
580
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
581
+ )
582
+ ;
583
+ $this->getConnection()->createTable($table);
584
+ }
585
+
586
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_package_items'))) {
587
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_package_items'));
588
+
589
+ $table
590
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
591
+ 'nullable' => false,
592
+ ))
593
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
594
+ 'nullable' => false,
595
+ ))
596
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
597
+ 'nullable' => true
598
+ ))
599
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
600
+ 'nullable' => true
601
+ ))
602
+ ->addForeignKey(
603
+ $this->getFkName('shipperhq_shipper/quote_package_items', 'package_id', 'shipperhq_shipper/quote_packages', 'package_id'),
604
+ 'package_id',
605
+ $this->getTable('shipperhq_shipper/quote_packages'),
606
+ 'package_id',
607
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
608
+ )
609
+ ;
610
+ $this->getConnection()->createTable($table);
611
+ }
612
+
613
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_packages'))) {
614
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_packages'));
615
+
616
+ $table
617
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
618
+ 'primary' => true,
619
+ 'nullable' => false,
620
+ 'unsigned' => true,
621
+ 'auto_increment' => true
622
+ ))
623
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
624
+ 'nullable' => false,
625
+ 'unsigned' => true
626
+ ))
627
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
628
+ 'nullable' => false,
629
+ ))
630
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
631
+ 'nullable' => false,
632
+ ))
633
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
634
+ 'nullable' => true
635
+ ))
636
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
637
+ 'nullable' => true
638
+ ))
639
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
640
+ 'nullable' => true
641
+ ))
642
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
643
+ 'nullable' => true
644
+ ))
645
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
646
+ 'nullable' => true
647
+ ))
648
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
649
+ 'nullable' => true
650
+ ))
651
+ ->addForeignKey(
652
+ $this->getFkName('shipperhq_shipper/order_packages', 'order_id', 'sales/order', 'entity_id'),
653
+ 'order_id',
654
+ $this->getTable('sales/order'),
655
+ 'entity_id',
656
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
657
+ )
658
+ ;
659
+ $this->getConnection()->createTable($table);
660
+ }
661
+
662
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_package_items'))) {
663
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_package_items'));
664
+
665
+ $table
666
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
667
+ 'nullable' => false,
668
+ 'unsigned' => true,
669
+ ))
670
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
671
+ 'nullable' => false,
672
+ ))
673
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
674
+ 'nullable' => true
675
+ ))
676
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
677
+ 'nullable' => true
678
+ ))
679
+ ->addForeignKey(
680
+ $this->getFkName('shipperhq_shipper/order_package_items', 'package_id', 'shipperhq_shipper/order_packages', 'package_id'),
681
+ 'package_id',
682
+ $this->getTable('shipperhq_shipper/order_packages'),
683
+ 'package_id',
684
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
685
+ )
686
+ ;
687
+ $this->getConnection()->createTable($table);
688
+ }
689
+
690
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.25.php ADDED
@@ -0,0 +1,816 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/attributeupdate'))) {
8
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/attributeupdate'));
9
+
10
+ $table
11
+ ->addColumn('synch_id', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array(
12
+ 'primary' => true,
13
+ 'nullable' => false,
14
+ 'unsigned' => true,
15
+ 'auto_increment' => true
16
+ ))
17
+ ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 0, array(
18
+ 'nullable' => false,
19
+ 'unsigned' => true,
20
+ ))
21
+ ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
22
+ 'nullable' => false,
23
+ ))
24
+ ->addColumn('attribute_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
25
+ 'nullable' => false,
26
+ ))
27
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
28
+ 'nullable' => false,
29
+ ))
30
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
31
+ 'nullable' => false,
32
+ ))
33
+ ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
34
+ 'nullable' => false,
35
+ ))
36
+ ;
37
+ $this->getConnection()->createTable($table);
38
+ }
39
+
40
+ /* ------ shipperhq_shipping_group -------- */
41
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_group', array(
42
+ 'type' => 'varchar',
43
+ 'backend' => 'eav/entity_attribute_backend_array',
44
+ 'input' => 'multiselect',
45
+ 'label' => 'Shipping Group',
46
+ 'global' => false,
47
+ 'visible' => 1,
48
+ 'required' => 0,
49
+ 'visible_on_front' => 0,
50
+ 'is_html_allowed_on_front' => 0,
51
+ 'searchable' => 0,
52
+ 'filterable' => 0,
53
+ 'comparable' => 0,
54
+ 'is_configurable' => 0,
55
+ 'unique' => false,
56
+ 'user_defined' => false,
57
+ 'used_in_product_listing' => false
58
+ ));
59
+
60
+ /* ------ shipperhq_warehouse -------- */
61
+ $this->addAttribute('catalog_product', 'shipperhq_warehouse', array(
62
+ 'type' => 'text',
63
+ 'backend' => 'eav/entity_attribute_backend_array',
64
+ 'input' => 'multiselect',
65
+ 'label' => 'Origin',
66
+ 'global' => false,
67
+ 'visible' => 1,
68
+ 'required' => 0,
69
+ 'visible_on_front' => 0,
70
+ 'is_html_allowed_on_front' => 0,
71
+ 'searchable' => 0,
72
+ 'filterable' => 0,
73
+ 'comparable' => 0,
74
+ 'is_configurable' => 0,
75
+ 'unique' => false,
76
+ 'user_defined' => false,
77
+ 'used_in_product_listing' => false
78
+ ));
79
+
80
+ /* ------ shipperhq_shipping_qty -------- */
81
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_qty', array(
82
+ 'type' => 'int',
83
+ 'input' => 'text',
84
+ 'label' => 'Shipping Qty',
85
+ 'global' => false,
86
+ 'visible' => 1,
87
+ 'required' => 0,
88
+ 'visible_on_front' => 0,
89
+ 'is_html_allowed_on_front' => 0,
90
+ 'searchable' => 0,
91
+ 'filterable' => 0,
92
+ 'comparable' => 0,
93
+ 'unique' => false,
94
+ 'user_defined' => true,
95
+ 'used_in_product_listing' => false
96
+ ));
97
+
98
+ /* ------ shipperhq_shipping_fee -------- */
99
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_fee', array(
100
+ 'type' => 'decimal',
101
+ 'input' => 'price',
102
+ 'label' => 'Shipping Fee',
103
+ 'global' => false,
104
+ 'visible' => 1,
105
+ 'required' => 0,
106
+ 'visible_on_front' => 0,
107
+ 'is_html_allowed_on_front' => 0,
108
+ 'searchable' => 0,
109
+ 'filterable' => 0,
110
+ 'comparable' => 0,
111
+ 'unique' => false,
112
+ 'user_defined' => true,
113
+ 'used_in_product_listing' => false
114
+ ));
115
+
116
+ /* ------ shipperhq_additional_price -------- */
117
+ $this->addAttribute('catalog_product', 'shipperhq_additional_price', array(
118
+ 'type' => 'decimal',
119
+ 'input' => 'price',
120
+ 'label' => 'Additional Price',
121
+ 'global' => false,
122
+ 'visible' => 1,
123
+ 'required' => 0,
124
+ 'visible_on_front' => 0,
125
+ 'is_html_allowed_on_front' => 0,
126
+ 'searchable' => 0,
127
+ 'filterable' => 0,
128
+ 'comparable' => 0,
129
+ 'unique' => false,
130
+ 'user_defined' => true,
131
+ 'used_in_product_listing' => false
132
+ ));
133
+
134
+ /* ------ shipperhq_handling_fee -------- */
135
+ $this->addAttribute('catalog_product', 'shipperhq_handling_fee', array(
136
+ 'type' => 'decimal',
137
+ 'input' => 'price',
138
+ 'label' => 'Handling Fee',
139
+ 'global' => false,
140
+ 'visible' => 1,
141
+ 'required' => 0,
142
+ 'visible_on_front' => 0,
143
+ 'is_html_allowed_on_front' => 0,
144
+ 'searchable' => 0,
145
+ 'filterable' => 0,
146
+ 'comparable' => 0,
147
+ 'unique' => false,
148
+ 'user_defined' => true,
149
+ 'used_in_product_listing' => false
150
+ ));
151
+
152
+ /* ------ shipperhq_carrier_code -------- */
153
+ $this->addAttribute('catalog_product', 'shipperhq_carrier_code', array(
154
+ 'type' => 'text',
155
+ 'input' => 'text',
156
+ 'label' => 'Carrier Code',
157
+ 'global' => false,
158
+ 'visible' => 1,
159
+ 'required' => 0,
160
+ 'visible_on_front' => 0,
161
+ 'is_html_allowed_on_front' => 0,
162
+ 'searchable' => 0,
163
+ 'filterable' => 0,
164
+ 'comparable' => 0,
165
+ 'unique' => false,
166
+ 'user_defined' => true,
167
+ 'used_in_product_listing' => false
168
+ ));
169
+
170
+ /* ------ shipperhq_volume_weight -------- */
171
+ $this->addAttribute('catalog_product', 'shipperhq_volume_weight', array(
172
+ 'type' => 'decimal',
173
+ 'input' => 'text',
174
+ 'label' => 'Volume Weight',
175
+ 'global' => false,
176
+ 'visible' => 1,
177
+ 'required' => 0,
178
+ 'visible_on_front' => 0,
179
+ 'is_html_allowed_on_front' => 0,
180
+ 'searchable' => 0,
181
+ 'filterable' => 0,
182
+ 'comparable' => 0,
183
+ 'unique' => false,
184
+ 'user_defined' => true,
185
+ 'used_in_product_listing' => false,
186
+ 'note' => 'This value is only used in conjunction with shipping filters'
187
+ ));
188
+
189
+ /* ------ shipperhq_declared_value -------- */
190
+ $this->addAttribute('catalog_product', 'shipperhq_declared_value', array(
191
+ 'type' => 'decimal',
192
+ 'input' => 'price',
193
+ 'label' => 'Declared Value',
194
+ 'global' => false,
195
+ 'visible' => 1,
196
+ 'required' => 0,
197
+ 'visible_on_front' => 0,
198
+ 'is_html_allowed_on_front' => 0,
199
+ 'searchable' => 0,
200
+ 'filterable' => 0,
201
+ 'comparable' => 0,
202
+ 'unique' => false,
203
+ 'user_defined' => true,
204
+ 'used_in_product_listing' => false,
205
+ 'note' => 'The deemed cost of this product for customs & insurance purposes'
206
+ ));
207
+
208
+ /* ------ ship_separately -------- */
209
+ $this->addAttribute('catalog_product', 'ship_separately', array(
210
+ 'type' => 'int',
211
+ 'input' => 'boolean',
212
+ 'label' => 'Ship Separately',
213
+ 'global' => false,
214
+ 'visible' => 1,
215
+ 'required' => 0,
216
+ 'visible_on_front' => 0,
217
+ 'is_html_allowed_on_front' => 0,
218
+ 'searchable' => 0,
219
+ 'filterable' => 0,
220
+ 'comparable' => 0,
221
+ 'unique' => false,
222
+ 'user_defined' => true,
223
+ 'used_in_product_listing' => false
224
+ ));
225
+
226
+ /* ------ shipperhq_dim_group -------- */
227
+ $this->addAttribute('catalog_product', 'shipperhq_dim_group', array(
228
+ 'type' => 'varchar',
229
+ 'input' => 'select',
230
+ 'label' => 'ShipperHQ Dimensional Rule Group',
231
+ 'backend' => 'eav/entity_attribute_backend_array',
232
+ 'global' => false,
233
+ 'visible' => 1,
234
+ 'required' => 0,
235
+ 'visible_on_front' => 0,
236
+ 'is_html_allowed_on_front' => 0,
237
+ 'searchable' => 0,
238
+ 'filterable' => 0,
239
+ 'comparable' => 0,
240
+ 'is_configurable' => 0,
241
+ 'unique' => false,
242
+ 'user_defined' => true,
243
+ 'used_in_product_listing' => false
244
+ ));
245
+
246
+ /* ------ ship_length -------- */
247
+ $this->addAttribute('catalog_product', 'ship_length', array(
248
+ 'type' => 'decimal',
249
+ 'input' => 'text',
250
+ 'label' => 'Dimension Length',
251
+ 'global' => false,
252
+ 'visible' => 1,
253
+ 'required' => 0,
254
+ 'visible_on_front' => 0,
255
+ 'is_html_allowed_on_front' => 0,
256
+ 'searchable' => 0,
257
+ 'filterable' => 0,
258
+ 'comparable' => 0,
259
+ 'unique' => false,
260
+ 'user_defined' => true,
261
+ 'used_in_product_listing' => false
262
+ ));
263
+
264
+ /* ------ ship_width -------- */
265
+ $this->addAttribute('catalog_product', 'ship_width', array(
266
+ 'type' => 'decimal',
267
+ 'input' => 'text',
268
+ 'label' => 'Dimension Width',
269
+ 'global' => false,
270
+ 'visible' => 1,
271
+ 'required' => 0,
272
+ 'visible_on_front' => 0,
273
+ 'is_html_allowed_on_front' => 0,
274
+ 'searchable' => 0,
275
+ 'filterable' => 0,
276
+ 'comparable' => 0,
277
+ 'unique' => false,
278
+ 'user_defined' => true,
279
+ 'used_in_product_listing' => false
280
+ ));
281
+
282
+ /* ------ ship_height -------- */
283
+ $this->addAttribute('catalog_product', 'ship_height', array(
284
+ 'type' => 'decimal',
285
+ 'input' => 'text',
286
+ 'label' => 'Dimension Height',
287
+ 'global' => false,
288
+ 'visible' => 1,
289
+ 'required' => 0,
290
+ 'visible_on_front' => 0,
291
+ 'is_html_allowed_on_front' => 0,
292
+ 'searchable' => 0,
293
+ 'filterable' => 0,
294
+ 'comparable' => 0,
295
+ 'unique' => false,
296
+ 'user_defined' => true,
297
+ 'used_in_product_listing' => false
298
+ ));
299
+
300
+ /* ------ shipperhq_poss_boxes -------- */
301
+ $this->addAttribute('catalog_product', 'shipperhq_poss_boxes', array(
302
+ 'type' => 'varchar',
303
+ 'backend' => 'eav/entity_attribute_backend_array',
304
+ 'input' => 'multiselect',
305
+ 'label' => 'Possible Packing Boxes',
306
+ 'global' => false,
307
+ 'visible' => 1,
308
+ 'required' => 0,
309
+ 'visible_on_front' => 0,
310
+ 'is_html_allowed_on_front' => 0,
311
+ 'searchable' => 0,
312
+ 'filterable' => 0,
313
+ 'comparable' => 0,
314
+ 'is_configurable' => 0,
315
+ 'unique' => false,
316
+ 'user_defined' => true,
317
+ 'used_in_product_listing' => false
318
+ ));
319
+
320
+ /* ------ ship_box_tolerance -------- */
321
+ $this->addAttribute('catalog_product', 'ship_box_tolerance', array(
322
+ 'type' => 'int',
323
+ 'input' => 'text',
324
+ 'label' => 'Box Tolerance',
325
+ 'global' => false,
326
+ 'visible' => 1,
327
+ 'required' => 0,
328
+ 'visible_on_front' => 0,
329
+ 'is_html_allowed_on_front' => 0,
330
+ 'searchable' => 0,
331
+ 'filterable' => 0,
332
+ 'comparable' => 0,
333
+ 'unique' => false,
334
+ 'used_in_product_listing' => false,
335
+ 'user_defined' => true,
336
+ 'note' => 'Note: Ignore if unsure'
337
+ ));
338
+
339
+ /*
340
+ *
341
+ *
342
+ *
343
+ */
344
+
345
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
346
+
347
+ $attributeSetArr = $installer->getAllAttributeSetIds($entityTypeId);
348
+
349
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Splitrates')) {
350
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1', 'shipperhq_warehouse' => '10');
351
+ }
352
+ else {
353
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
354
+ }
355
+ $dimAttributeCodes = array('ship_separately' => '2',
356
+ 'shipperhq_dim_group' => '1',
357
+ 'ship_length' => '10',
358
+ 'ship_width' => '11',
359
+ 'ship_height' => '12',
360
+ 'shipperhq_poss_boxes' => '20',
361
+ );
362
+
363
+ foreach ($attributeSetArr as $attributeSetId) {
364
+
365
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
366
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
367
+
368
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
369
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
370
+
371
+ foreach($stdAttributeCodes as $code => $sort) {
372
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
373
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
374
+ }
375
+
376
+ foreach($dimAttributeCodes as $code => $sort) {
377
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
378
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
379
+ }
380
+
381
+ };
382
+
383
+
384
+
385
+ $text = Mage::helper('wsalogger')->getNewVersion() > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : 'text';
386
+
387
+ $isCheckout = array(
388
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
389
+ 'comment' => 'Shipperhq Shipper',
390
+ 'nullable' => 'false',
391
+ 'default' => '0'
392
+ );
393
+
394
+ $carrierType = array(
395
+ 'type' => $text,
396
+ 'comment' => 'Shipperhq Carrier Type',
397
+ 'nullable' => 'true',
398
+ );
399
+
400
+ $dispatchDate = array(
401
+ 'type' => $text,
402
+ 'length' => 20,
403
+ 'comment' => 'Dispatch Date',
404
+ 'nullable' => 'true');
405
+
406
+ $deliveryDate = array(
407
+ 'type' => $text,
408
+ 'length' => 20,
409
+ 'comment' => 'Expected Delivery',
410
+ 'nullable' => 'true');
411
+
412
+ $carrierNotice = array(
413
+ 'type' => $text,
414
+ 'comment' => 'Shipperhq Carrier Notice',
415
+ 'nullable' => 'true',
416
+ );
417
+
418
+ $customDescription = array(
419
+ 'type' => $text,
420
+ 'comment' => 'Shipperhq Custom Description',
421
+ 'nullable' => 'true',
422
+ );
423
+
424
+ $carrierId = array(
425
+ 'type' => $text,
426
+ 'length' => 20,
427
+ 'comment' => 'Shipperhq Carrier ID',
428
+ 'nullable' => 'true',
429
+ );
430
+
431
+ $customDuties = array(
432
+ 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
433
+ 'scale' => 4,
434
+ 'precision' => 12,
435
+ 'comment' => 'Shipperhq Custom Duties',
436
+ );
437
+
438
+ $confirmationNo = array(
439
+ 'type' => $text,
440
+ 'length' => 20,
441
+ 'comment' => 'Shipperhq Confirmation Number',
442
+ 'nullable' => 'true',
443
+ );
444
+
445
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'is_checkout')){
446
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
447
+ }
448
+
449
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carrier_type')){
450
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
451
+ }
452
+
453
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'dispatch_date')){
454
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
455
+ }
456
+
457
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'delivery_date')){
458
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
459
+ }
460
+
461
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type')){
462
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
463
+ }
464
+
465
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'dispatch_date')){
466
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
467
+ }
468
+
469
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'delivery_date')){
470
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
471
+ }
472
+
473
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice')){
474
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
475
+ }
476
+
477
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'custom_description')){
478
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'custom_description', $customDescription);
479
+ }
480
+
481
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_id')){
482
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_id', $carrierId);
483
+ }
484
+
485
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carrier_id')){
486
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'carrier_id', $carrierId );
487
+ }
488
+
489
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carrier_id')){
490
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_id', $carrierId );
491
+ }
492
+
493
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'confirmation_number')){
494
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'confirmation_number', $confirmationNo );
495
+ }
496
+
497
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'custom_duties')){
498
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'custom_duties', $customDuties);
499
+ }
500
+
501
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carrier_type')){
502
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
503
+ }
504
+
505
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'dispatch_date')){
506
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
507
+ }
508
+
509
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'delivery_date')){
510
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
511
+ }
512
+
513
+ /*carrier group attributes*/
514
+ $version = Mage::helper('wsalogger')->getNewVersion();
515
+
516
+ $carriergroupAttr = array(
517
+ 'type' => $version > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : Varien_Db_Ddl_Table::TYPE_VARCHAR,
518
+ 'comment' => 'Carrier Group',
519
+ 'nullable' => 'true',
520
+ );
521
+
522
+ $carriergroupID = array(
523
+ 'type' => $version > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : Varien_Db_Ddl_Table::TYPE_VARCHAR,
524
+ 'comment' => 'Carrier Group ID',
525
+ 'nullable' => 'true',
526
+ );
527
+
528
+ $carriergroupDetails = array(
529
+ 'type' => $version > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : Varien_Db_Ddl_Table::TYPE_VARCHAR,
530
+ 'comment' => 'Carrier Group Details',
531
+ 'nullable' => 'true',
532
+ );
533
+
534
+ $carriergroupHtml = array(
535
+ 'type' => $version > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : Varien_Db_Ddl_Table::TYPE_VARCHAR,
536
+ 'comment' => 'Carrier Group Html',
537
+ 'nullable' => 'true',
538
+ );
539
+
540
+ $displayMerged = array(
541
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
542
+ 'comment' => 'Checkout display type',
543
+ 'nullable' => 'false',
544
+ 'default' => '1'
545
+ );
546
+
547
+ $splitRates = array(
548
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
549
+ 'comment' => 'Shipperhq Split Rates',
550
+ 'nullable' => 'false',
551
+ 'default' => '0'
552
+ );
553
+
554
+ $carriergroupShipping = array(
555
+ 'type' => $version > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : Varien_Db_Ddl_Table::TYPE_VARCHAR,
556
+ 'comment' => 'Shipping Description',
557
+ 'nullable' => 'true',
558
+ );
559
+
560
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carriergroup_shipping_details')){
561
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carriergroup_shipping_details', $carriergroupDetails);
562
+ }
563
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carriergroup_shipping_html')){
564
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carriergroup_shipping_html', $carriergroupHtml);
565
+ }
566
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'checkout_display_merged')){
567
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'checkout_display_merged', $displayMerged);
568
+ }
569
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'split_rates')){
570
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'split_rates', $splitRates);
571
+ }
572
+
573
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carriergroup_id')){
574
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carriergroup_id', $carriergroupID);
575
+ }
576
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carriergroup')){
577
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carriergroup', $carriergroupAttr);
578
+ }
579
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carriergroup_shipping_details')){
580
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carriergroup_shipping_details', $carriergroupDetails);
581
+ }
582
+
583
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_item'), 'carriergroup')){
584
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_item'), 'carriergroup', $carriergroupAttr);
585
+ }
586
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order_item'), 'carriergroup')){
587
+ $installer->getConnection()->addColumn($installer->getTable('sales/order_item'), 'carriergroup', $carriergroupAttr);
588
+ }
589
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_item'), 'carriergroup_id')){
590
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_item'), 'carriergroup_id', $carriergroupID);
591
+ }
592
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order_item'), 'carriergroup_id')){
593
+ $installer->getConnection()->addColumn($installer->getTable('sales/order_item'), 'carriergroup_id', $carriergroupID);
594
+ }
595
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_item'), 'carriergroup_shipping')){
596
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_item'), 'carriergroup_shipping', $carriergroupShipping);
597
+ }
598
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order_item'), 'carriergroup_shipping')){
599
+ $installer->getConnection()->addColumn($installer->getTable('sales/order_item'), 'carriergroup_shipping', $carriergroupShipping);
600
+ }
601
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_item'), 'carriergroup_shipping')){
602
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_item'), 'carriergroup_shipping', $carriergroupShipping);
603
+ }
604
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_item'), 'carriergroup')){
605
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_item'), 'carriergroup', $carriergroupAttr);
606
+ }
607
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_item'), 'carriergroup_id')){
608
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_item'), 'carriergroup_id', $carriergroupID);
609
+ }
610
+
611
+
612
+ if (Mage::helper('wsalogger')->getNewVersion() >= 8) {
613
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/shipment_grid'), 'carriergroup')){
614
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment_grid'),'carriergroup',$carriergroupAttr);
615
+ }
616
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/shipment'), 'carriergroup')){
617
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment'),'carriergroup',$carriergroupAttr);
618
+ }
619
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/shipment'), 'shipping_description')){
620
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment'),'shipping_description',array(
621
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
622
+ 'length' => 255,
623
+ 'comment' => 'Shipping Description',
624
+ 'nullable' => 'true',));
625
+ }
626
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carriergroup_shipping_html')){
627
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'carriergroup_shipping_html', $carriergroupHtml);
628
+ }
629
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carriergroup_shipping_details')){
630
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'carriergroup_shipping_details', $carriergroupDetails);
631
+ }
632
+ if (Mage::helper('wsalogger')->isEnterpriseEdition() && $installer->tableExists('enterprise_sales_shipment_grid_archive')) {
633
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('enterprise_sales_shipment_grid_archive'), 'carriergroup')){
634
+ $installer->getConnection()->addColumn($installer->getTable('enterprise_sales_shipment_grid_archive'),'carriergroup',$carriergroupAttr);
635
+ }
636
+ }
637
+ }
638
+
639
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/storage'))) {
640
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/storage'));
641
+
642
+ $table
643
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
644
+ 'primary' => true,
645
+ 'nullable' => false,
646
+ 'unsigned' => true
647
+ ))
648
+ ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '512k', array('nullable' => false))
649
+ ->addForeignKey(
650
+ $this->getFkName('shipperhq_shipper/storage', 'quote_id', 'sales/quote', 'entity_id'),
651
+ 'quote_id',
652
+ $this->getTable('sales/quote'),
653
+ 'entity_id',
654
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
655
+ )
656
+ ;
657
+ $this->getConnection()->createTable($table);
658
+ }
659
+
660
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_packages'))) {
661
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_packages'));
662
+
663
+ $table
664
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
665
+ 'primary' => true,
666
+ 'nullable' => false,
667
+ 'unsigned' => true,
668
+ 'auto_increment' => true
669
+ ))
670
+ ->addColumn('address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
671
+ 'nullable' => false,
672
+ 'unsigned' => true
673
+ ))
674
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
675
+ 'nullable' => false,
676
+ ))
677
+ ->addColumn('carrier_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
678
+ 'nullable' => false,
679
+ ))
680
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
681
+ 'nullable' => false,
682
+ ))
683
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
684
+ 'nullable' => true
685
+ ))
686
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
687
+ 'nullable' => true
688
+ ))
689
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
690
+ 'nullable' => true
691
+ ))
692
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
693
+ 'nullable' => true
694
+ ))
695
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
696
+ 'nullable' => true
697
+ ))
698
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
699
+ 'nullable' => true
700
+ ))
701
+ ->addForeignKey(
702
+ $this->getFkName('shipperhq_shipper/quote_packages', 'address_id', 'sales/quote_address', 'address_id'),
703
+ 'address_id',
704
+ $this->getTable('sales/quote_address'),
705
+ 'address_id',
706
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
707
+ )
708
+ ;
709
+ $this->getConnection()->createTable($table);
710
+ }
711
+
712
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_package_items'))) {
713
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_package_items'));
714
+
715
+ $table
716
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
717
+ 'nullable' => false,
718
+ ))
719
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
720
+ 'nullable' => false,
721
+ ))
722
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
723
+ 'nullable' => true
724
+ ))
725
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
726
+ 'nullable' => true
727
+ ))
728
+ ->addForeignKey(
729
+ $this->getFkName('shipperhq_shipper/quote_package_items', 'package_id', 'shipperhq_shipper/quote_packages', 'package_id'),
730
+ 'package_id',
731
+ $this->getTable('shipperhq_shipper/quote_packages'),
732
+ 'package_id',
733
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
734
+ )
735
+ ;
736
+ $this->getConnection()->createTable($table);
737
+ }
738
+
739
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_packages'))) {
740
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_packages'));
741
+
742
+ $table
743
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
744
+ 'primary' => true,
745
+ 'nullable' => false,
746
+ 'unsigned' => true,
747
+ 'auto_increment' => true
748
+ ))
749
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
750
+ 'nullable' => false,
751
+ 'unsigned' => true
752
+ ))
753
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
754
+ 'nullable' => false,
755
+ ))
756
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
757
+ 'nullable' => false,
758
+ ))
759
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
760
+ 'nullable' => true
761
+ ))
762
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
763
+ 'nullable' => true
764
+ ))
765
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
766
+ 'nullable' => true
767
+ ))
768
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
769
+ 'nullable' => true
770
+ ))
771
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
772
+ 'nullable' => true
773
+ ))
774
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
775
+ 'nullable' => true
776
+ ))
777
+ ->addForeignKey(
778
+ $this->getFkName('shipperhq_shipper/order_packages', 'order_id', 'sales/order', 'entity_id'),
779
+ 'order_id',
780
+ $this->getTable('sales/order'),
781
+ 'entity_id',
782
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
783
+ )
784
+ ;
785
+ $this->getConnection()->createTable($table);
786
+ }
787
+
788
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_package_items'))) {
789
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_package_items'));
790
+
791
+ $table
792
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
793
+ 'nullable' => false,
794
+ 'unsigned' => true,
795
+ ))
796
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
797
+ 'nullable' => false,
798
+ ))
799
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
800
+ 'nullable' => true
801
+ ))
802
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
803
+ 'nullable' => true
804
+ ))
805
+ ->addForeignKey(
806
+ $this->getFkName('shipperhq_shipper/order_package_items', 'package_id', 'shipperhq_shipper/order_packages', 'package_id'),
807
+ 'package_id',
808
+ $this->getTable('shipperhq_shipper/order_packages'),
809
+ 'package_id',
810
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
811
+ )
812
+ ;
813
+ $this->getConnection()->createTable($table);
814
+ }
815
+
816
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.26.php ADDED
@@ -0,0 +1,836 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/attributeupdate'))) {
8
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/attributeupdate'));
9
+
10
+ $table
11
+ ->addColumn('synch_id', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array(
12
+ 'primary' => true,
13
+ 'nullable' => false,
14
+ 'unsigned' => true,
15
+ 'auto_increment' => true
16
+ ))
17
+ ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 0, array(
18
+ 'nullable' => false,
19
+ 'unsigned' => true,
20
+ ))
21
+ ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
22
+ 'nullable' => false,
23
+ ))
24
+ ->addColumn('attribute_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
25
+ 'nullable' => false,
26
+ ))
27
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
28
+ 'nullable' => false,
29
+ ))
30
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
31
+ 'nullable' => false,
32
+ ))
33
+ ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
34
+ 'nullable' => false,
35
+ ))
36
+ ;
37
+ $this->getConnection()->createTable($table);
38
+ }
39
+
40
+ /* ------ shipperhq_shipping_group -------- */
41
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_group', array(
42
+ 'type' => 'varchar',
43
+ 'backend' => 'eav/entity_attribute_backend_array',
44
+ 'input' => 'multiselect',
45
+ 'label' => 'Shipping Group',
46
+ 'global' => false,
47
+ 'visible' => 1,
48
+ 'required' => 0,
49
+ 'visible_on_front' => 0,
50
+ 'is_html_allowed_on_front' => 0,
51
+ 'searchable' => 0,
52
+ 'filterable' => 0,
53
+ 'comparable' => 0,
54
+ 'is_configurable' => 0,
55
+ 'unique' => false,
56
+ 'user_defined' => false,
57
+ 'used_in_product_listing' => false
58
+ ));
59
+
60
+ /* ------ shipperhq_warehouse -------- */
61
+ $this->addAttribute('catalog_product', 'shipperhq_warehouse', array(
62
+ 'type' => 'text',
63
+ 'backend' => 'eav/entity_attribute_backend_array',
64
+ 'input' => 'multiselect',
65
+ 'label' => 'Origin',
66
+ 'global' => false,
67
+ 'visible' => 1,
68
+ 'required' => 0,
69
+ 'visible_on_front' => 0,
70
+ 'is_html_allowed_on_front' => 0,
71
+ 'searchable' => 0,
72
+ 'filterable' => 0,
73
+ 'comparable' => 0,
74
+ 'is_configurable' => 0,
75
+ 'unique' => false,
76
+ 'user_defined' => false,
77
+ 'used_in_product_listing' => false
78
+ ));
79
+
80
+ /* ------ shipperhq_shipping_qty -------- */
81
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_qty', array(
82
+ 'type' => 'int',
83
+ 'input' => 'text',
84
+ 'label' => 'Shipping Qty',
85
+ 'global' => false,
86
+ 'visible' => 1,
87
+ 'required' => 0,
88
+ 'visible_on_front' => 0,
89
+ 'is_html_allowed_on_front' => 0,
90
+ 'searchable' => 0,
91
+ 'filterable' => 0,
92
+ 'comparable' => 0,
93
+ 'unique' => false,
94
+ 'user_defined' => true,
95
+ 'used_in_product_listing' => false
96
+ ));
97
+
98
+ /* ------ shipperhq_shipping_fee -------- */
99
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_fee', array(
100
+ 'type' => 'decimal',
101
+ 'input' => 'price',
102
+ 'label' => 'Shipping Fee',
103
+ 'global' => false,
104
+ 'visible' => 1,
105
+ 'required' => 0,
106
+ 'visible_on_front' => 0,
107
+ 'is_html_allowed_on_front' => 0,
108
+ 'searchable' => 0,
109
+ 'filterable' => 0,
110
+ 'comparable' => 0,
111
+ 'unique' => false,
112
+ 'user_defined' => true,
113
+ 'used_in_product_listing' => false
114
+ ));
115
+
116
+ /* ------ shipperhq_additional_price -------- */
117
+ $this->addAttribute('catalog_product', 'shipperhq_additional_price', array(
118
+ 'type' => 'decimal',
119
+ 'input' => 'price',
120
+ 'label' => 'Additional Price',
121
+ 'global' => false,
122
+ 'visible' => 1,
123
+ 'required' => 0,
124
+ 'visible_on_front' => 0,
125
+ 'is_html_allowed_on_front' => 0,
126
+ 'searchable' => 0,
127
+ 'filterable' => 0,
128
+ 'comparable' => 0,
129
+ 'unique' => false,
130
+ 'user_defined' => true,
131
+ 'used_in_product_listing' => false
132
+ ));
133
+
134
+ /* ------ shipperhq_handling_fee -------- */
135
+ $this->addAttribute('catalog_product', 'shipperhq_handling_fee', array(
136
+ 'type' => 'decimal',
137
+ 'input' => 'price',
138
+ 'label' => 'Handling Fee',
139
+ 'global' => false,
140
+ 'visible' => 1,
141
+ 'required' => 0,
142
+ 'visible_on_front' => 0,
143
+ 'is_html_allowed_on_front' => 0,
144
+ 'searchable' => 0,
145
+ 'filterable' => 0,
146
+ 'comparable' => 0,
147
+ 'unique' => false,
148
+ 'user_defined' => true,
149
+ 'used_in_product_listing' => false
150
+ ));
151
+
152
+ /* ------ shipperhq_carrier_code -------- */
153
+ $this->addAttribute('catalog_product', 'shipperhq_carrier_code', array(
154
+ 'type' => 'text',
155
+ 'input' => 'text',
156
+ 'label' => 'Carrier Code',
157
+ 'global' => false,
158
+ 'visible' => 1,
159
+ 'required' => 0,
160
+ 'visible_on_front' => 0,
161
+ 'is_html_allowed_on_front' => 0,
162
+ 'searchable' => 0,
163
+ 'filterable' => 0,
164
+ 'comparable' => 0,
165
+ 'unique' => false,
166
+ 'user_defined' => true,
167
+ 'used_in_product_listing' => false
168
+ ));
169
+
170
+ /* ------ shipperhq_volume_weight -------- */
171
+ $this->addAttribute('catalog_product', 'shipperhq_volume_weight', array(
172
+ 'type' => 'decimal',
173
+ 'input' => 'text',
174
+ 'label' => 'Volume Weight',
175
+ 'global' => false,
176
+ 'visible' => 1,
177
+ 'required' => 0,
178
+ 'visible_on_front' => 0,
179
+ 'is_html_allowed_on_front' => 0,
180
+ 'searchable' => 0,
181
+ 'filterable' => 0,
182
+ 'comparable' => 0,
183
+ 'unique' => false,
184
+ 'user_defined' => true,
185
+ 'used_in_product_listing' => false,
186
+ 'note' => 'This value is only used in conjunction with shipping filters'
187
+ ));
188
+
189
+ /* ------ shipperhq_declared_value -------- */
190
+ $this->addAttribute('catalog_product', 'shipperhq_declared_value', array(
191
+ 'type' => 'decimal',
192
+ 'input' => 'price',
193
+ 'label' => 'Declared Value',
194
+ 'global' => false,
195
+ 'visible' => 1,
196
+ 'required' => 0,
197
+ 'visible_on_front' => 0,
198
+ 'is_html_allowed_on_front' => 0,
199
+ 'searchable' => 0,
200
+ 'filterable' => 0,
201
+ 'comparable' => 0,
202
+ 'unique' => false,
203
+ 'user_defined' => true,
204
+ 'used_in_product_listing' => false,
205
+ 'note' => 'The deemed cost of this product for customs & insurance purposes'
206
+ ));
207
+
208
+ /* ------ ship_separately -------- */
209
+ $this->addAttribute('catalog_product', 'ship_separately', array(
210
+ 'type' => 'int',
211
+ 'input' => 'boolean',
212
+ 'label' => 'Ship Separately',
213
+ 'global' => false,
214
+ 'visible' => 1,
215
+ 'required' => 0,
216
+ 'visible_on_front' => 0,
217
+ 'is_html_allowed_on_front' => 0,
218
+ 'searchable' => 0,
219
+ 'filterable' => 0,
220
+ 'comparable' => 0,
221
+ 'unique' => false,
222
+ 'user_defined' => true,
223
+ 'used_in_product_listing' => false
224
+ ));
225
+
226
+ /* ------ shipperhq_dim_group -------- */
227
+ $this->addAttribute('catalog_product', 'shipperhq_dim_group', array(
228
+ 'type' => 'varchar',
229
+ 'input' => 'select',
230
+ 'label' => 'ShipperHQ Dimensional Rule Group',
231
+ 'backend' => 'eav/entity_attribute_backend_array',
232
+ 'global' => false,
233
+ 'visible' => 1,
234
+ 'required' => 0,
235
+ 'visible_on_front' => 0,
236
+ 'is_html_allowed_on_front' => 0,
237
+ 'searchable' => 0,
238
+ 'filterable' => 0,
239
+ 'comparable' => 0,
240
+ 'is_configurable' => 0,
241
+ 'unique' => false,
242
+ 'user_defined' => true,
243
+ 'used_in_product_listing' => false
244
+ ));
245
+
246
+ /* ------ ship_length -------- */
247
+ $this->addAttribute('catalog_product', 'ship_length', array(
248
+ 'type' => 'decimal',
249
+ 'input' => 'text',
250
+ 'label' => 'Dimension Length',
251
+ 'global' => false,
252
+ 'visible' => 1,
253
+ 'required' => 0,
254
+ 'visible_on_front' => 0,
255
+ 'is_html_allowed_on_front' => 0,
256
+ 'searchable' => 0,
257
+ 'filterable' => 0,
258
+ 'comparable' => 0,
259
+ 'unique' => false,
260
+ 'user_defined' => true,
261
+ 'used_in_product_listing' => false
262
+ ));
263
+
264
+ /* ------ ship_width -------- */
265
+ $this->addAttribute('catalog_product', 'ship_width', array(
266
+ 'type' => 'decimal',
267
+ 'input' => 'text',
268
+ 'label' => 'Dimension Width',
269
+ 'global' => false,
270
+ 'visible' => 1,
271
+ 'required' => 0,
272
+ 'visible_on_front' => 0,
273
+ 'is_html_allowed_on_front' => 0,
274
+ 'searchable' => 0,
275
+ 'filterable' => 0,
276
+ 'comparable' => 0,
277
+ 'unique' => false,
278
+ 'user_defined' => true,
279
+ 'used_in_product_listing' => false
280
+ ));
281
+
282
+ /* ------ ship_height -------- */
283
+ $this->addAttribute('catalog_product', 'ship_height', array(
284
+ 'type' => 'decimal',
285
+ 'input' => 'text',
286
+ 'label' => 'Dimension Height',
287
+ 'global' => false,
288
+ 'visible' => 1,
289
+ 'required' => 0,
290
+ 'visible_on_front' => 0,
291
+ 'is_html_allowed_on_front' => 0,
292
+ 'searchable' => 0,
293
+ 'filterable' => 0,
294
+ 'comparable' => 0,
295
+ 'unique' => false,
296
+ 'user_defined' => true,
297
+ 'used_in_product_listing' => false
298
+ ));
299
+
300
+ /* ------ shipperhq_poss_boxes -------- */
301
+ $this->addAttribute('catalog_product', 'shipperhq_poss_boxes', array(
302
+ 'type' => 'varchar',
303
+ 'backend' => 'eav/entity_attribute_backend_array',
304
+ 'input' => 'multiselect',
305
+ 'label' => 'Possible Packing Boxes',
306
+ 'global' => false,
307
+ 'visible' => 1,
308
+ 'required' => 0,
309
+ 'visible_on_front' => 0,
310
+ 'is_html_allowed_on_front' => 0,
311
+ 'searchable' => 0,
312
+ 'filterable' => 0,
313
+ 'comparable' => 0,
314
+ 'is_configurable' => 0,
315
+ 'unique' => false,
316
+ 'user_defined' => true,
317
+ 'used_in_product_listing' => false
318
+ ));
319
+
320
+ /* ------ ship_box_tolerance -------- */
321
+ $this->addAttribute('catalog_product', 'ship_box_tolerance', array(
322
+ 'type' => 'int',
323
+ 'input' => 'text',
324
+ 'label' => 'Box Tolerance',
325
+ 'global' => false,
326
+ 'visible' => 1,
327
+ 'required' => 0,
328
+ 'visible_on_front' => 0,
329
+ 'is_html_allowed_on_front' => 0,
330
+ 'searchable' => 0,
331
+ 'filterable' => 0,
332
+ 'comparable' => 0,
333
+ 'unique' => false,
334
+ 'used_in_product_listing' => false,
335
+ 'user_defined' => true,
336
+ 'note' => 'Note: Ignore if unsure'
337
+ ));
338
+
339
+ /* ------ shipperhq_malleable_product -------- */
340
+ $this->addAttribute('catalog_product', 'shipperhq_malleable_product', array(
341
+ 'type' => 'int',
342
+ 'input' => 'boolean',
343
+ 'label' => 'Malleable Product',
344
+ 'global' => false,
345
+ 'visible' => 1,
346
+ 'required' => 0,
347
+ 'visible_on_front' => 0,
348
+ 'is_html_allowed_on_front' => 0,
349
+ 'searchable' => 0,
350
+ 'filterable' => 0,
351
+ 'comparable' => 0,
352
+ 'unique' => false,
353
+ 'user_defined' => true,
354
+ 'note' => 'Ignore if unsure. Indicates the product dimensions can be adjusted to fit box',
355
+ 'used_in_product_listing' => false
356
+ ));
357
+
358
+
359
+ /*
360
+ *
361
+ *
362
+ *
363
+ */
364
+
365
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
366
+
367
+ $attributeSetArr = $installer->getAllAttributeSetIds($entityTypeId);
368
+
369
+ if(Mage::helper('shipperhq_shipper')->isModuleEnabled('Shipperhq_Splitrates')) {
370
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1', 'shipperhq_warehouse' => '10');
371
+ }
372
+ else {
373
+ $stdAttributeCodes = array('shipperhq_shipping_group' => '1');
374
+ }
375
+ $dimAttributeCodes = array('ship_separately' => '2',
376
+ 'shipperhq_dim_group' => '1',
377
+ 'ship_length' => '10',
378
+ 'ship_width' => '11',
379
+ 'ship_height' => '12',
380
+ 'shipperhq_poss_boxes' => '20',
381
+ );
382
+
383
+ foreach ($attributeSetArr as $attributeSetId) {
384
+
385
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Shipping', '99');
386
+ $installer->addAttributeGroup($entityTypeId, $attributeSetId, 'Dimensional Shipping', '100');
387
+
388
+ $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Shipping');
389
+ $dimAttributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dimensional Shipping');
390
+
391
+ foreach($stdAttributeCodes as $code => $sort) {
392
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
393
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, $sort);
394
+ }
395
+
396
+ foreach($dimAttributeCodes as $code => $sort) {
397
+ $attributeId = $installer->getAttributeId($entityTypeId, $code);
398
+ $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $dimAttributeGroupId, $attributeId, $sort);
399
+ }
400
+
401
+ };
402
+
403
+
404
+
405
+ $text = Mage::helper('wsalogger')->getNewVersion() > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : 'text';
406
+
407
+ $isCheckout = array(
408
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
409
+ 'comment' => 'Shipperhq Shipper',
410
+ 'nullable' => 'false',
411
+ 'default' => '0'
412
+ );
413
+
414
+ $carrierType = array(
415
+ 'type' => $text,
416
+ 'comment' => 'Shipperhq Carrier Type',
417
+ 'nullable' => 'true',
418
+ );
419
+
420
+ $dispatchDate = array(
421
+ 'type' => $text,
422
+ 'length' => 20,
423
+ 'comment' => 'Dispatch Date',
424
+ 'nullable' => 'true');
425
+
426
+ $deliveryDate = array(
427
+ 'type' => $text,
428
+ 'length' => 20,
429
+ 'comment' => 'Expected Delivery',
430
+ 'nullable' => 'true');
431
+
432
+ $carrierNotice = array(
433
+ 'type' => $text,
434
+ 'comment' => 'Shipperhq Carrier Notice',
435
+ 'nullable' => 'true',
436
+ );
437
+
438
+ $customDescription = array(
439
+ 'type' => $text,
440
+ 'comment' => 'Shipperhq Custom Description',
441
+ 'nullable' => 'true',
442
+ );
443
+
444
+ $carrierId = array(
445
+ 'type' => $text,
446
+ 'length' => 20,
447
+ 'comment' => 'Shipperhq Carrier ID',
448
+ 'nullable' => 'true',
449
+ );
450
+
451
+ $customDuties = array(
452
+ 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
453
+ 'scale' => 4,
454
+ 'precision' => 12,
455
+ 'comment' => 'Shipperhq Custom Duties',
456
+ );
457
+
458
+ $confirmationNo = array(
459
+ 'type' => $text,
460
+ 'length' => 20,
461
+ 'comment' => 'Shipperhq Confirmation Number',
462
+ 'nullable' => 'true',
463
+ );
464
+
465
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'is_checkout')){
466
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'is_checkout', $isCheckout);
467
+ }
468
+
469
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carrier_type')){
470
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carrier_type', $carrierType);
471
+ }
472
+
473
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'dispatch_date')){
474
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'dispatch_date', $dispatchDate );
475
+ }
476
+
477
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'delivery_date')){
478
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'delivery_date', $deliveryDate );
479
+ }
480
+
481
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type')){
482
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_type', $carrierType);
483
+ }
484
+
485
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'dispatch_date')){
486
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'dispatch_date', $dispatchDate );
487
+ }
488
+
489
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'delivery_date')){
490
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'),'delivery_date', $deliveryDate );
491
+ }
492
+
493
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice')){
494
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_notice', $carrierNotice);
495
+ }
496
+
497
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'custom_description')){
498
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'custom_description', $customDescription);
499
+ }
500
+
501
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_id')){
502
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carrier_id', $carrierId);
503
+ }
504
+
505
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carrier_id')){
506
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),'carrier_id', $carrierId );
507
+ }
508
+
509
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carrier_id')){
510
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_id', $carrierId );
511
+ }
512
+
513
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'confirmation_number')){
514
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'confirmation_number', $confirmationNo );
515
+ }
516
+
517
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'custom_duties')){
518
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'custom_duties', $customDuties);
519
+ }
520
+
521
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carrier_type')){
522
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'carrier_type', $carrierType );
523
+ }
524
+
525
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'dispatch_date')){
526
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'dispatch_date', $dispatchDate );
527
+ }
528
+
529
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'delivery_date')){
530
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),'delivery_date', $deliveryDate );
531
+ }
532
+
533
+ /*carrier group attributes*/
534
+ $version = Mage::helper('wsalogger')->getNewVersion();
535
+
536
+ $carriergroupAttr = array(
537
+ 'type' => $version > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : Varien_Db_Ddl_Table::TYPE_VARCHAR,
538
+ 'comment' => 'Carrier Group',
539
+ 'nullable' => 'true',
540
+ );
541
+
542
+ $carriergroupID = array(
543
+ 'type' => $version > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : Varien_Db_Ddl_Table::TYPE_VARCHAR,
544
+ 'comment' => 'Carrier Group ID',
545
+ 'nullable' => 'true',
546
+ );
547
+
548
+ $carriergroupDetails = array(
549
+ 'type' => $version > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : Varien_Db_Ddl_Table::TYPE_VARCHAR,
550
+ 'comment' => 'Carrier Group Details',
551
+ 'nullable' => 'true',
552
+ );
553
+
554
+ $carriergroupHtml = array(
555
+ 'type' => $version > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : Varien_Db_Ddl_Table::TYPE_VARCHAR,
556
+ 'comment' => 'Carrier Group Html',
557
+ 'nullable' => 'true',
558
+ );
559
+
560
+ $displayMerged = array(
561
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
562
+ 'comment' => 'Checkout display type',
563
+ 'nullable' => 'false',
564
+ 'default' => '1'
565
+ );
566
+
567
+ $splitRates = array(
568
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
569
+ 'comment' => 'Shipperhq Split Rates',
570
+ 'nullable' => 'false',
571
+ 'default' => '0'
572
+ );
573
+
574
+ $carriergroupShipping = array(
575
+ 'type' => $version > 10 ? Varien_Db_Ddl_Table::TYPE_TEXT : Varien_Db_Ddl_Table::TYPE_VARCHAR,
576
+ 'comment' => 'Shipping Description',
577
+ 'nullable' => 'true',
578
+ );
579
+
580
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carriergroup_shipping_details')){
581
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carriergroup_shipping_details', $carriergroupDetails);
582
+ }
583
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'carriergroup_shipping_html')){
584
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'carriergroup_shipping_html', $carriergroupHtml);
585
+ }
586
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'checkout_display_merged')){
587
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'checkout_display_merged', $displayMerged);
588
+ }
589
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address'), 'split_rates')){
590
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'), 'split_rates', $splitRates);
591
+ }
592
+
593
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carriergroup_id')){
594
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carriergroup_id', $carriergroupID);
595
+ }
596
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carriergroup')){
597
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carriergroup', $carriergroupAttr);
598
+ }
599
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_shipping_rate'), 'carriergroup_shipping_details')){
600
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_shipping_rate'), 'carriergroup_shipping_details', $carriergroupDetails);
601
+ }
602
+
603
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_item'), 'carriergroup')){
604
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_item'), 'carriergroup', $carriergroupAttr);
605
+ }
606
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order_item'), 'carriergroup')){
607
+ $installer->getConnection()->addColumn($installer->getTable('sales/order_item'), 'carriergroup', $carriergroupAttr);
608
+ }
609
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_item'), 'carriergroup_id')){
610
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_item'), 'carriergroup_id', $carriergroupID);
611
+ }
612
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order_item'), 'carriergroup_id')){
613
+ $installer->getConnection()->addColumn($installer->getTable('sales/order_item'), 'carriergroup_id', $carriergroupID);
614
+ }
615
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_item'), 'carriergroup_shipping')){
616
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_item'), 'carriergroup_shipping', $carriergroupShipping);
617
+ }
618
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order_item'), 'carriergroup_shipping')){
619
+ $installer->getConnection()->addColumn($installer->getTable('sales/order_item'), 'carriergroup_shipping', $carriergroupShipping);
620
+ }
621
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_item'), 'carriergroup_shipping')){
622
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_item'), 'carriergroup_shipping', $carriergroupShipping);
623
+ }
624
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_item'), 'carriergroup')){
625
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_item'), 'carriergroup', $carriergroupAttr);
626
+ }
627
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/quote_address_item'), 'carriergroup_id')){
628
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address_item'), 'carriergroup_id', $carriergroupID);
629
+ }
630
+
631
+
632
+ if (Mage::helper('wsalogger')->getNewVersion() >= 8) {
633
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/shipment_grid'), 'carriergroup')){
634
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment_grid'),'carriergroup',$carriergroupAttr);
635
+ }
636
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/shipment'), 'carriergroup')){
637
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment'),'carriergroup',$carriergroupAttr);
638
+ }
639
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/shipment'), 'shipping_description')){
640
+ $installer->getConnection()->addColumn($installer->getTable('sales/shipment'),'shipping_description',array(
641
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
642
+ 'length' => 255,
643
+ 'comment' => 'Shipping Description',
644
+ 'nullable' => 'true',));
645
+ }
646
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carriergroup_shipping_html')){
647
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'carriergroup_shipping_html', $carriergroupHtml);
648
+ }
649
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('sales/order'), 'carriergroup_shipping_details')){
650
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'carriergroup_shipping_details', $carriergroupDetails);
651
+ }
652
+ if (Mage::helper('wsalogger')->isEnterpriseEdition() && $installer->tableExists('enterprise_sales_shipment_grid_archive')) {
653
+ if(!$installer->getConnection()->tableColumnExists($installer->getTable('enterprise_sales_shipment_grid_archive'), 'carriergroup')){
654
+ $installer->getConnection()->addColumn($installer->getTable('enterprise_sales_shipment_grid_archive'),'carriergroup',$carriergroupAttr);
655
+ }
656
+ }
657
+ }
658
+
659
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/storage'))) {
660
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/storage'));
661
+
662
+ $table
663
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
664
+ 'primary' => true,
665
+ 'nullable' => false,
666
+ 'unsigned' => true
667
+ ))
668
+ ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '512k', array('nullable' => false))
669
+ ->addForeignKey(
670
+ $this->getFkName('shipperhq_shipper/storage', 'quote_id', 'sales/quote', 'entity_id'),
671
+ 'quote_id',
672
+ $this->getTable('sales/quote'),
673
+ 'entity_id',
674
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
675
+ )
676
+ ;
677
+ $this->getConnection()->createTable($table);
678
+ }
679
+
680
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_packages'))) {
681
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_packages'));
682
+
683
+ $table
684
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
685
+ 'primary' => true,
686
+ 'nullable' => false,
687
+ 'unsigned' => true,
688
+ 'auto_increment' => true
689
+ ))
690
+ ->addColumn('address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
691
+ 'nullable' => false,
692
+ 'unsigned' => true
693
+ ))
694
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
695
+ 'nullable' => false,
696
+ ))
697
+ ->addColumn('carrier_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
698
+ 'nullable' => false,
699
+ ))
700
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
701
+ 'nullable' => false,
702
+ ))
703
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
704
+ 'nullable' => true
705
+ ))
706
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
707
+ 'nullable' => true
708
+ ))
709
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
710
+ 'nullable' => true
711
+ ))
712
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
713
+ 'nullable' => true
714
+ ))
715
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
716
+ 'nullable' => true
717
+ ))
718
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
719
+ 'nullable' => true
720
+ ))
721
+ ->addForeignKey(
722
+ $this->getFkName('shipperhq_shipper/quote_packages', 'address_id', 'sales/quote_address', 'address_id'),
723
+ 'address_id',
724
+ $this->getTable('sales/quote_address'),
725
+ 'address_id',
726
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
727
+ )
728
+ ;
729
+ $this->getConnection()->createTable($table);
730
+ }
731
+
732
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/quote_package_items'))) {
733
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/quote_package_items'));
734
+
735
+ $table
736
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
737
+ 'nullable' => false,
738
+ ))
739
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
740
+ 'nullable' => false,
741
+ ))
742
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
743
+ 'nullable' => true
744
+ ))
745
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
746
+ 'nullable' => true
747
+ ))
748
+ ->addForeignKey(
749
+ $this->getFkName('shipperhq_shipper/quote_package_items', 'package_id', 'shipperhq_shipper/quote_packages', 'package_id'),
750
+ 'package_id',
751
+ $this->getTable('shipperhq_shipper/quote_packages'),
752
+ 'package_id',
753
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
754
+ )
755
+ ;
756
+ $this->getConnection()->createTable($table);
757
+ }
758
+
759
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_packages'))) {
760
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_packages'));
761
+
762
+ $table
763
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
764
+ 'primary' => true,
765
+ 'nullable' => false,
766
+ 'unsigned' => true,
767
+ 'auto_increment' => true
768
+ ))
769
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
770
+ 'nullable' => false,
771
+ 'unsigned' => true
772
+ ))
773
+ ->addColumn('carrier_group_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
774
+ 'nullable' => false,
775
+ ))
776
+ ->addColumn('package_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
777
+ 'nullable' => false,
778
+ ))
779
+ ->addColumn('length', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
780
+ 'nullable' => true
781
+ ))
782
+ ->addColumn('width', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
783
+ 'nullable' => true
784
+ ))
785
+ ->addColumn('height', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
786
+ 'nullable' => true
787
+ ))
788
+ ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
789
+ 'nullable' => true
790
+ ))
791
+ ->addColumn('declared_value', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
792
+ 'nullable' => true
793
+ ))
794
+ ->addColumn('surcharge_price', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
795
+ 'nullable' => true
796
+ ))
797
+ ->addForeignKey(
798
+ $this->getFkName('shipperhq_shipper/order_packages', 'order_id', 'sales/order', 'entity_id'),
799
+ 'order_id',
800
+ $this->getTable('sales/order'),
801
+ 'entity_id',
802
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
803
+ )
804
+ ;
805
+ $this->getConnection()->createTable($table);
806
+ }
807
+
808
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/order_package_items'))) {
809
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/order_package_items'));
810
+
811
+ $table
812
+ ->addColumn('package_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
813
+ 'nullable' => false,
814
+ 'unsigned' => true,
815
+ ))
816
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
817
+ 'nullable' => false,
818
+ ))
819
+ ->addColumn('qty_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
820
+ 'nullable' => true
821
+ ))
822
+ ->addColumn('weight_packed', Varien_Db_Ddl_Table::TYPE_FLOAT , array(
823
+ 'nullable' => true
824
+ ))
825
+ ->addForeignKey(
826
+ $this->getFkName('shipperhq_shipper/order_package_items', 'package_id', 'shipperhq_shipper/order_packages', 'package_id'),
827
+ 'package_id',
828
+ $this->getTable('shipperhq_shipper/order_packages'),
829
+ 'package_id',
830
+ Varien_Db_Adapter_Interface::FK_ACTION_CASCADE
831
+ )
832
+ ;
833
+ $this->getConnection()->createTable($table);
834
+ }
835
+
836
+ $installer->endSetup();
app/code/community/Shipperhq/Shipper/sql/shipperhq_shipper_setup/mysql4-install-0.0.27.php ADDED
@@ -0,0 +1,850 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ if(!$installer->getConnection()->isTableExists($this->getTable('shipperhq_shipper/attributeupdate'))) {
8
+ $table = $this->getConnection()->newTable($this->getTable('shipperhq_shipper/attributeupdate'));
9
+
10
+ $table
11
+ ->addColumn('synch_id', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array(
12
+ 'primary' => true,
13
+ 'nullable' => false,
14
+ 'unsigned' => true,
15
+ 'auto_increment' => true
16
+ ))
17
+ ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 0, array(
18
+ 'nullable' => false,
19
+ 'unsigned' => true,
20
+ ))
21
+ ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
22
+ 'nullable' => false,
23
+ ))
24
+ ->addColumn('attribute_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
25
+ 'nullable' => false,
26
+ ))
27
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
28
+ 'nullable' => false,
29
+ ))
30
+ ->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, NULL, array(
31
+ 'nullable' => false,
32
+ ))
33
+ ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
34
+ 'nullable' => false,
35
+ ))
36
+ ;
37
+ $this->getConnection()->createTable($table);
38
+ }
39
+
40
+ /* ------ shipperhq_shipping_group -------- */
41
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_group', array(
42
+ 'type' => 'varchar',
43
+ 'backend' => 'eav/entity_attribute_backend_array',
44
+ 'input' => 'multiselect',
45
+ 'label' => 'Shipping Group',
46
+ 'global' => false,
47
+ 'visible' => 1,
48
+ 'required' => 0,
49
+ 'visible_on_front' => 0,
50
+ 'is_html_allowed_on_front' => 0,
51
+ 'searchable' => 0,
52
+ 'filterable' => 0,
53
+ 'comparable' => 0,
54
+ 'is_configurable' => 0,
55
+ 'unique' => false,
56
+ 'user_defined' => false,
57
+ 'used_in_product_listing' => false
58
+ ));
59
+
60
+ /* ------ shipperhq_warehouse -------- */
61
+ $this->addAttribute('catalog_product', 'shipperhq_warehouse', array(
62
+ 'type' => 'text',
63
+ 'backend' => 'eav/entity_attribute_backend_array',
64
+ 'input' => 'multiselect',
65
+ 'label' => 'Origin',
66
+ 'global' => false,
67
+ 'visible' => 1,
68
+ 'required' => 0,
69
+ 'visible_on_front' => 0,
70
+ 'is_html_allowed_on_front' => 0,
71
+ 'searchable' => 0,
72
+ 'filterable' => 0,
73
+ 'comparable' => 0,
74
+ 'is_configurable' => 0,
75
+ 'unique' => false,
76
+ 'user_defined' => false,
77
+ 'used_in_product_listing' => false
78
+ ));
79
+
80
+ /* ------ shipperhq_shipping_qty -------- */
81
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_qty', array(
82
+ 'type' => 'int',
83
+ 'input' => 'text',
84
+ 'label' => 'Shipping Qty',
85
+ 'global' => false,
86
+ 'visible' => 1,
87
+ 'required' => 0,
88
+ 'visible_on_front' => 0,
89
+ 'is_html_allowed_on_front' => 0,
90
+ 'searchable' => 0,
91
+ 'filterable' => 0,
92
+ 'comparable' => 0,
93
+ 'unique' => false,
94
+ 'user_defined' => true,
95
+ 'used_in_product_listing' => false
96
+ ));
97
+
98
+ /* ------ shipperhq_shipping_fee -------- */
99
+ $this->addAttribute('catalog_product', 'shipperhq_shipping_fee', array(
100
+ 'type' => 'decimal',
101
+ 'input' => 'price',
102
+ 'label' => 'Shipping Fee',
103
+ 'global' => false,
104
+ 'visible' => 1,
105
+ 'required' => 0,
106
+ 'visible_on_front' => 0,
107
+ 'is_html_allowed_on_front' => 0,
108
+ 'searchable' => 0,
109
+ 'filterable' => 0,
110
+ 'comparable' => 0,
111
+ 'unique' => false,
112
+ 'user_defined' => true,
113
+ 'used_in_product_listing' => false
114
+ ));
115
+
116
+ /* ------ shipperhq_additional_price -------- */
117
+ $this->addAttribute('catalog_product', 'shipperhq_additional_price', array(
118
+ 'type' => 'decimal',
119
+ 'input' => 'price',
120
+ 'label' => 'Additional Price',
121
+ 'global' => false,
122
+ 'visible' => 1,
123
+ 'required' => 0,
124
+ 'visible_on_front' => 0,
125
+ 'is_html_allowed_on_front' => 0,
126
+ 'searchable' => 0,
127
+ 'filterable' => 0,
128
+ 'comparable' => 0,
129
+ 'unique' => false,
130
+ 'user_defined' => true,
131
+ 'used_in_product_listing' => false
132
+ ));
133
+
134
+ /* ------ shipperhq_handling_fee -------- */
135
+ $this->addAttribute('catalog_product', 'shipperhq_handling_fee', array(
136
+ 'type' => 'decimal',
137
+ 'input' => 'price',
138
+ 'label' => 'Handling Fee',
139
+ 'global' => false,
140
+ 'visible' => 1,
141
+ 'required' => 0,
142
+ 'visible_on_front' => 0,
143
+ 'is_html_allowed_on_front' => 0,
144
+ 'searchable' => 0,
145
+ 'filterable' => 0,
146
+ 'comparable' => 0,
147
+ 'unique' => false,
148
+ 'user_defined' => true,
149
+ 'used_in_product_listing' => false
150
+ ));
151
+
152
+ /* ------ shipperhq_carrier_code -------- */
153
+ $this->addAttribute('catalog_product', 'shipperhq_carrier_code', array(
154
+ 'type' => 'text',
155
+ 'input' => 'text',
156
+ 'label' => 'Carrier Code',
157
+ 'global' => false,
158
+ 'visible' => 1,
159
+ 'required' => 0,
160
+ 'visible_on_front' => 0,
161
+ 'is_html_allowed_on_front' => 0,
162
+ 'searchable' => 0,
163
+ 'filterable' => 0,
164
+ 'comparable' => 0,
165
+ 'unique' => false,
166
+ 'user_defined' => true,
167
+ 'used_in_product_listing' => false
168
+ ));
169
+
170
+ /* ------ shipperhq_volume_weight -------- */
171
+ $this->addAttribute('catalog_product', 'shipperhq_volume_weight', array(
172
+ 'type' => 'decimal',
173
+ 'input' => 'text',
174
+ 'label' => 'Volume Weight',
175
+ 'global' => false,
176
+ 'visible' => 1,
177
+ 'required' => 0,
178
+ 'visible_on_front' => 0,
179
+ 'is_html_allowed_on_front' => 0,
180
+ 'searchable' => 0,
181
+ 'filterable' => 0,
182
+ 'comparable' => 0,
183
+ 'unique' => false,
184
+ 'user_defined' => true,
185
+ 'used_in_product_listing' => false,
186
+ 'note' => 'This value is only used in conjunction with shipping filters'
187
+ ));
188
+
189
+ /* ------ shipperhq_declared_value -------- */
190
+ $this->addAttribute('catalog_product', 'shipperhq_declared_value', array(
191
+ 'type' => 'decimal',
192
+ 'input' => 'price',
193
+ 'label' => 'Declared Value',
194
+ 'global' => false,
195
+ 'visible' => 1,
196
+ 'required' => 0,
197
+ 'visible_on_front' => 0,
198
+ 'is_html_allowed_on_front' => 0,
199
+ 'searchable' => 0,
200
+ 'filterable' => 0,
201
+ 'comparable' => 0,
202
+ 'unique' => false,
203
+ 'user_defined' => true,
204
+ 'used_in_product_listing' => false,
205
+ 'note' => 'The deemed cost of this product for customs & insurance purposes'
206
+ ));
207
+
208
+ /* ------ ship_separately -------- */
209
+ $this->addAttribute('catalog_product', 'ship_separately', array(
210
+ 'type' => 'int',
211
+ 'input' => 'boolean',
212
+ 'label' => 'Ship Separately',
213
+ 'global' => false,
214
+ 'visible' => 1,
215
+ 'required' => 0,
216
+ 'visible_on_front' => 0,
217
+ 'is_html_allowed_on_front' => 0,
218
+ 'searchable' => 0,
219
+ 'filterable' => 0,
220
+ 'comparable' => 0,
221
+ 'unique' => false,
222
+ 'user_defined' => true,
223
+ 'used_in_product_listing' => false
224
+ ));
225
+
226
+ /* ------ shipperhq_dim_group -------- */
227
+ $this->addAttribute('catalog_product', 'shipperhq_dim_group', array(
228
+ 'type' => 'varchar',
229
+ 'input' => 'select',
230
+ 'label' => 'ShipperHQ Dimensional Rule Group',
231
+ 'backend' => 'eav/entity_attribute_backend_array',
232
+ 'global' => false,
233
+ 'visible' => 1,
234
+ 'required' => 0,
235
+ 'visible_on_front' => 0,
236
+ 'is_html_allowed_on_front' => 0,
237
+ 'searchable' => 0,
238
+ 'filterable' => 0,
239
+ 'comparable' => 0,
240
+ 'is_configurable' => 0,
241
+ 'unique' => false,
242
+ 'user_defined' => true,
243
+ 'used_in_product_listing' => false
244
+ ));
245
+
246
+ /* ------ ship_length -------- */
247
+ $this->addAttribute('catalog_product', 'ship_length', array(
248
+ 'type' => 'decimal',
249
+ 'input' => 'text',
250
+ 'label' => 'Dimension Length',
251
+ 'global' => false,
252
+ 'visible' => 1,
253
+ 'required' => 0,
254
+ 'visible_on_front' => 0,
255
+ 'is_html_allowed_on_front' => 0,
256
+ 'searchable' => 0,
257
+ 'filterable' => 0,
258
+ 'comparable' => 0,
259
+ 'unique' => false,
260
+ 'user_defined' => true,
261
+ 'used_in_product_listing' => false
262
+ ));
263
+
264
+ /* ------ ship_width -------- */
265
+ $this->addAttribute('catalog_product', 'ship_width', array(
266
+ 'type' => 'decimal',
267
+ 'input' => 'text',
268
+ 'label' => 'Dimension Width',
269
+ 'global' => false,
270
+ 'visible' => 1,
271
+ 'required' => 0,
272
+ 'visible_on_front' => 0,
273
+ 'is_html_allowed_on_front' => 0,
274
+ 'searchable' => 0,
275
+ 'filterable' => 0,
276
+ 'comparable' => 0,
277
+ 'unique' => false,
278
+ 'user_defined' => true,
279
+ 'used_in_product_listing' => false
280
+ ));
281
+
282
+ /* ------ ship_height -------- */
283
+ $this->addAttribute('catalog_product', 'ship_height', array(
284
+ 'type' => 'decimal',
285
+ 'input' => 'text',
286
+ 'label' => 'Dimension Height',
287
+ 'global' => false,
288
+ 'visible' => 1,
289
+ 'required' => 0,
290
+ 'visible_on_front' => 0,
291
+ 'is_html_allowed_on_front' => 0,
292
+ 'searchable' => 0,
293
+ 'filterable' => 0,
294
+ 'comparable' => 0,
295
+ 'unique' => false,
296
+ 'user_defined' => true,
297
+ 'used_in_product_listing' => false
298
+ ));
299
+
300
+ /* ------ shipperhq_poss_boxes -------- */
301
+ $this->addAttribute('catalog_product', 'shipperhq_poss_boxes', array(
302
+ 'type' => 'varchar',
303
+ 'backend' => 'eav/entity_attribute_backend_array',
304
+ 'input' => 'multiselect',
305
+ 'label' => 'Possible Packing Boxes',
306
+ 'global' => false,
307
+ 'visible' => 1,
308
+ 'required' => 0,
309
+ 'visible_on_front' => 0,
310
+ 'is_html_allowed_on_front' => 0,
311
+ 'searchable' => 0,
312
+ 'filterable' => 0,
313
+ 'comparable' => 0,
314
+ 'is_configurable' => 0,
315
+ 'unique' => false,
316
+ 'user_defined' => true,
317
+ 'used_in_product_listing' => false
318
+ ));
319
+
320
+ /* ------ ship_box_tolerance -------- */
321
+ $this->addAttribute('catalog_product', 'ship_box_tolerance', array(
322
+ 'type' => 'int',
323
+ 'input' => 'text',
324
+ 'label' => 'Box Tolerance',
325
+ 'global' => false,
326
+ 'visible' => 1,
327
+ 'required' => 0,
328
+ 'visible_on_front' => 0,
329
+ 'is_html_allowed_on_front' => 0,
330
+ 'searchable' => 0,
331
+ 'filterable' => 0,
332
+ 'comparable' => 0,
333
+ 'unique' => false,
334
+ 'used_in_product_listing' => false,
335
+ 'user_defined' => true,
336
+ 'note' => 'Note: Ignore if unsure'
337
+ ));
338
+
339
+ /* ------ shipperhq_malleable_product -------- */
340
+ $this->addAttribute('catalog_product', 'shipperhq_malleable_product', array(
341
+ 'type' => 'int',
342
+ 'input' => 'boolean',
343
+ 'label' => 'Malleable Product',
344
+ 'global' => false,
345
+ 'visible' => 1,
346
+ 'required' => 0,
347
+ 'visible_on_front' => 0,
348
+ 'is_html_allowed_on_front' => 0,
349
+ 'searchable' => 0,
350
+ 'filterable' => 0,
351
+ 'comparable' => 0,
352
+ 'unique' => false,
353
+ 'user_defined' => true,
354
+ 'note' =>