Mage_Shipwire - Version 1.2.1

Version Notes

Shipwire Shipping Rating API integrated

1.2.1
- Fixed issue with ship-to postcode not passing

Download this release

Release Info

Developer Magento Core Team
Extension Mage_Shipwire
Version 1.2.1
Comparing to
See all releases


Code changes from version 1.2.0 to 1.2.1

app/code/local/Shipwire/Shipping/Model/Carrier/ShippingMethod.php CHANGED
@@ -1,214 +1,215 @@
1
- <?php
2
-
3
- /**
4
- * Our test shipping method module adapter
5
- */
6
-
7
- class Shipwire_Shipping_Model_Carrier_ShippingMethod extends Mage_Shipping_Model_Carrier_Abstract
8
- {
9
-
10
- /**
11
- * unique internal shipping method identifier
12
- *
13
- * @var string [a-z0-9_]
14
- */
15
-
16
- protected $_code = 'shipwire_shipping';
17
-
18
- /**
19
- * Collect rates for this shipping method based on information in $request
20
- *
21
- * @param Mage_Shipping_Model_Rate_Request $data
22
- * @return Mage_Shipping_Model_Rate_Result
23
- */
24
- public function collectRates(Mage_Shipping_Model_Rate_Request $request)
25
- {
26
- // skip if not enabled
27
- if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active')) {
28
- return false;
29
- }
30
-
31
- /**
32
- * here we are retrieving shipping rates from external service
33
- * or using internal logic to calculate the rate from $request
34
- * you can see an example in Mage_Usa_Model_Shipping_Carrier_Ups::setRequest()
35
- */
36
- // get necessary configuration values
37
- $response = $this->_submitRequest($request);
38
- //$handling = Mage::getStoreConfig('carriers/'.$this->_code.'/handling');
39
-
40
- // this object will be returned as result of this method
41
- // containing all the shipping rates of this method
42
- $result = Mage::getModel('shipping/rate_result');
43
- // $response is an array that we have
44
- foreach ($response as $rMethod) {
45
- // create new instance of method rate
46
- $method = Mage::getModel('shipping/rate_result_method');
47
- // record carrier information
48
- $method->setCarrier($this->_code);
49
- $method->setCarrierTitle(Mage::getStoreConfig('carriers/'.$this->_code.'/title'));
50
- // record method information
51
- $method->setMethod($rMethod['code']);
52
- $method->setMethodTitle($rMethod['title']);
53
-
54
- // rate cost is optional property to record how much it costs to vendor to ship
55
- $method->setCost($rMethod['amount']);
56
-
57
- // in our example handling is fixed amount that is added to cost
58
- // to receive price the customer will pay for shipping method.
59
- // it could be as well percentage:
60
- /// $method->setPrice($rMethod['amount']*$handling/100);
61
- $method->setPrice($rMethod['amount']);
62
-
63
- // add this rate to the result
64
- $result->append($method);
65
- }
66
-
67
- return $result;
68
- }
69
-
70
-
71
- public function getAllowedMethods()
72
- {
73
- return array('shipwire_shipping'=>$this->getConfigData('name'));
74
- }
75
-
76
- private function _submitRequest($requestVar)
77
- {
78
-
79
- $account_email = Mage::getStoreConfig('carriers/shipwire_shipping/shipwire_email');
80
- $account_password = Mage::getStoreConfig('carriers/shipwire_shipping/shipwire_password');
81
- $available_services = Mage::getStoreConfig('carriers/shipwire_shipping/availableservices');
82
-
83
- $address_street1 = $requestVar->dest_street;
84
- $address_street2 = '';
85
- $address_city = $requestVar->dest_city;
86
- $address_region = $requestVar->dest_region_code;
87
- $address_country = $requestVar->dest_country_id;
88
- $address_postcode =
89
- !empty($requestVar->dest_postcode)
90
- ? $requestVar->dest_postcode
91
- : (!empty($requestVar->dest_zip)
92
- ? $requestVar->dest_zip
93
- : $requestVar->postcode);
94
-
95
- $items = $requestVar->all_items;
96
-
97
- $item_xml = '';
98
- $num = 1;
99
- if (count($items) > 0) {
100
- foreach ($items as $item) {
101
- $item_xml .= '<Item num="' . $num++ . '">';
102
- $item_xml .= '<Code>' . htmlentities($item->sku) . '</Code>';
103
- $item_xml .= '<Quantity>' . htmlentities($item->qty) . '</Quantity>';
104
- $item_xml .= '</Item>';
105
- }
106
- }
107
-
108
- $xml = '
109
- <RateRequest>
110
- <EmailAddress><![CDATA[' . $account_email . ']]></EmailAddress>
111
- <Password><![CDATA[' . $account_password . ']]></Password>
112
- <Order id="quote123">
113
- <Warehouse>00</Warehouse>
114
- <AddressInfo type="ship">
115
- <Address1><![CDATA[' . htmlentities($address_street1) . ']]></Address1>
116
- <Address2><![CDATA[' . htmlentities($address_street2) . ']]></Address2>
117
- <City><![CDATA[' . htmlentities($address_city) . ']]></City>
118
- <State><![CDATA[' . htmlentities($address_region) . ']]></State>
119
- <Country><![CDATA[' . htmlentities($address_country) . ']]></Country>
120
- <Zip><![CDATA[' . htmlentities($address_postcode) . ']]></Zip>
121
- </AddressInfo>
122
- ' . $item_xml . '
123
- </Order>
124
- </RateRequest>';
125
-
126
- $xml_request_encoded = ("RateRequestXML=" . $xml);
127
-
128
- $xml_submit_url = "https://api.shipwire.com/exec/RateServices.php";
129
-
130
- $session = curl_init();
131
- curl_setopt($session, CURLOPT_URL, $xml_submit_url);
132
- curl_setopt($session, CURLOPT_POST, true);
133
- curl_setopt($session, CURLOPT_HTTPHEADER, array("Content-type","application/x-www-form-urlencoded"));
134
- curl_setopt($session, CURLOPT_POSTFIELDS, $xml_request_encoded);
135
- curl_setopt($session, CURLOPT_HEADER, false);
136
- curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
137
- curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
138
- curl_setopt($session, CURLOPT_TIMEOUT, 360);
139
- $response = curl_exec($session);
140
- /*
141
- $client = new Varien_Http_Client('https://api.shipwire.com/exec/RateServices.php');
142
- $client->setMethod(Zend_Http_Client::POST);
143
- $client->setParameterPost('RateRequestXML', $xml);
144
- $response = $client->request();
145
- */
146
- $rateResult = array();
147
- if (FALSE === $response) {
148
- $rateResult;
149
- }
150
-
151
- $parser = xml_parser_create();
152
-
153
- xml_parse_into_struct($parser, $response, $xmlVals, $xmlIndex);
154
-
155
- xml_parser_free($parser);
156
-
157
- foreach($xmlVals as $key){
158
- if($key['tag'] == "STATUS"){
159
- if($key['value'] != "OK"){
160
- return $rateResult;
161
- }
162
-
163
- }
164
- }
165
-
166
- $code = array();
167
- $method = array();
168
- $cost = array();
169
- $supportedServices = explode(",", $available_services);
170
-
171
- foreach($xmlVals as $key){
172
- if($key['tag'] == "QUOTE" && $key['type'] == "open" && $key['level'] == 4) {
173
- $code[] = $key['attributes']['METHOD'];
174
- }
175
- if($key['tag'] == "SERVICE" && $key['type'] == "complete" && $key['level'] == 5) {
176
- $method[] = $key['value'];
177
- }
178
- if($key['tag'] == "COST" && $key['type'] == "complete" && $key['level'] == 5) {
179
- $cost[] = $key['value'];
180
- }
181
- }
182
-
183
- $la = count($code);
184
- $lb = count($method);
185
- $lc = count($cost);
186
-
187
- if($la = $lb = $lc){
188
- foreach($code as $index => $value){
189
- if (in_array($value, $supportedServices)) {
190
- $rateResult[] = array("code" => $code[$index],
191
- "title" => $method[$index],
192
- "amount" =>$cost[$index]) ;
193
- }
194
- }
195
- }
196
- return $rateResult;
197
-
198
- }
199
-
200
- protected function _formatResponse($response) {
201
- $values = array();
202
- $index = array();
203
-
204
- $p = xml_parser_create();
205
- xml_parse_into_struct($p, $response->getBody(), $values, $index);
206
- xml_parser_free($p);
207
-
208
- //print_r($values);
209
- //print_r($index);
210
- $exceptions = array();
211
- $warnings = array();
212
- }
213
-
214
- }
 
1
+ <?php
2
+
3
+ /**
4
+ * Our test shipping method module adapter
5
+ */
6
+
7
+ class Shipwire_Shipping_Model_Carrier_ShippingMethod extends Mage_Shipping_Model_Carrier_Abstract
8
+ {
9
+
10
+ /**
11
+ * unique internal shipping method identifier
12
+ *
13
+ * @var string [a-z0-9_]
14
+ */
15
+
16
+ protected $_code = 'shipwire_shipping';
17
+
18
+ /**
19
+ * Collect rates for this shipping method based on information in $request
20
+ *
21
+ * @param Mage_Shipping_Model_Rate_Request $data
22
+ * @return Mage_Shipping_Model_Rate_Result
23
+ */
24
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
25
+ {
26
+ // skip if not enabled
27
+ if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active')) {
28
+ return false;
29
+ }
30
+
31
+ /**
32
+ * here we are retrieving shipping rates from external service
33
+ * or using internal logic to calculate the rate from $request
34
+ * you can see an example in Mage_Usa_Model_Shipping_Carrier_Ups::setRequest()
35
+ */
36
+ // get necessary configuration values
37
+ $response = $this->_submitRequest($request);
38
+ //$handling = Mage::getStoreConfig('carriers/'.$this->_code.'/handling');
39
+
40
+ // this object will be returned as result of this method
41
+ // containing all the shipping rates of this method
42
+ $result = Mage::getModel('shipping/rate_result');
43
+ // $response is an array that we have
44
+ foreach ($response as $rMethod) {
45
+ // create new instance of method rate
46
+ $method = Mage::getModel('shipping/rate_result_method');
47
+ // record carrier information
48
+ $method->setCarrier($this->_code);
49
+ $method->setCarrierTitle(Mage::getStoreConfig('carriers/'.$this->_code.'/title'));
50
+ // record method information
51
+ $method->setMethod($rMethod['code']);
52
+ $method->setMethodTitle($rMethod['title']);
53
+
54
+ // rate cost is optional property to record how much it costs to vendor to ship
55
+ $method->setCost($rMethod['amount']);
56
+
57
+ // in our example handling is fixed amount that is added to cost
58
+ // to receive price the customer will pay for shipping method.
59
+ // it could be as well percentage:
60
+ /// $method->setPrice($rMethod['amount']*$handling/100);
61
+ $method->setPrice($rMethod['amount']);
62
+
63
+ // add this rate to the result
64
+ $result->append($method);
65
+ }
66
+
67
+ return $result;
68
+ }
69
+
70
+
71
+ public function getAllowedMethods()
72
+ {
73
+ return array('shipwire_shipping'=>$this->getConfigData('name'));
74
+ }
75
+
76
+ private function _submitRequest($requestVar)
77
+ {
78
+
79
+ $account_email = Mage::getStoreConfig('carriers/shipwire_shipping/shipwire_email');
80
+ $account_password = Mage::getStoreConfig('carriers/shipwire_shipping/shipwire_password');
81
+ $available_services = Mage::getStoreConfig('carriers/shipwire_shipping/availableservices');
82
+
83
+ $address_street1 = $requestVar->dest_street;
84
+ $address_street2 = '';
85
+ $address_city = $requestVar->dest_city;
86
+ $address_region = $requestVar->dest_region_code;
87
+ $address_country = $requestVar->dest_country_id;
88
+ $address_postcode =
89
+ !empty($requestVar->dest_postcode)
90
+ ? $requestVar->dest_postcode
91
+ : (!empty($requestVar->dest_zip)
92
+ ? $requestVar->dest_zip
93
+ : $requestVar->getDestPostcode());
94
+
95
+ $items = $requestVar->all_items;
96
+
97
+ $item_xml = '';
98
+ $num = 1;
99
+ if (count($items) > 0) {
100
+ foreach ($items as $item) {
101
+ $item_xml .= '<Item num="' . $num++ . '">';
102
+ $item_xml .= '<Code>' . htmlentities($item->sku) . '</Code>';
103
+ $item_xml .= '<Quantity>' . htmlentities($item->qty) . '</Quantity>';
104
+ $item_xml .= '</Item>';
105
+ }
106
+ }
107
+
108
+ $xml = '
109
+ <RateRequest>
110
+ <EmailAddress><![CDATA[' . $account_email . ']]></EmailAddress>
111
+ <Password><![CDATA[' . $account_password . ']]></Password>
112
+ <Source>Magento Rating Module 1.2.0a</Source>
113
+ <Order id="quote123">
114
+ <Warehouse>00</Warehouse>
115
+ <AddressInfo type="ship">
116
+ <Address1><![CDATA[' . htmlentities($address_street1) . ']]></Address1>
117
+ <Address2><![CDATA[' . htmlentities($address_street2) . ']]></Address2>
118
+ <City><![CDATA[' . htmlentities($address_city) . ']]></City>
119
+ <State><![CDATA[' . htmlentities($address_region) . ']]></State>
120
+ <Country><![CDATA[' . htmlentities($address_country) . ']]></Country>
121
+ <Zip><![CDATA[' . htmlentities($address_postcode) . ']]></Zip>
122
+ </AddressInfo>
123
+ ' . $item_xml . '
124
+ </Order>
125
+ </RateRequest>';
126
+
127
+ $xml_request_encoded = ("RateRequestXML=" . $xml);
128
+
129
+ $xml_submit_url = "https://api.shipwire.com/exec/RateServices.php";
130
+
131
+ $session = curl_init();
132
+ curl_setopt($session, CURLOPT_URL, $xml_submit_url);
133
+ curl_setopt($session, CURLOPT_POST, true);
134
+ curl_setopt($session, CURLOPT_HTTPHEADER, array("Content-type","application/x-www-form-urlencoded"));
135
+ curl_setopt($session, CURLOPT_POSTFIELDS, $xml_request_encoded);
136
+ curl_setopt($session, CURLOPT_HEADER, false);
137
+ curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
138
+ curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
139
+ curl_setopt($session, CURLOPT_TIMEOUT, 360);
140
+ $response = curl_exec($session);
141
+ /*
142
+ $client = new Varien_Http_Client('https://api.shipwire.com/exec/RateServices.php');
143
+ $client->setMethod(Zend_Http_Client::POST);
144
+ $client->setParameterPost('RateRequestXML', $xml);
145
+ $response = $client->request();
146
+ */
147
+ $rateResult = array();
148
+ if (FALSE === $response) {
149
+ $rateResult;
150
+ }
151
+
152
+ $parser = xml_parser_create();
153
+
154
+ xml_parse_into_struct($parser, $response, $xmlVals, $xmlIndex);
155
+
156
+ xml_parser_free($parser);
157
+
158
+ foreach($xmlVals as $key){
159
+ if($key['tag'] == "STATUS"){
160
+ if($key['value'] != "OK"){
161
+ return $rateResult;
162
+ }
163
+
164
+ }
165
+ }
166
+
167
+ $code = array();
168
+ $method = array();
169
+ $cost = array();
170
+ $supportedServices = explode(",", $available_services);
171
+
172
+ foreach($xmlVals as $key){
173
+ if($key['tag'] == "QUOTE" && $key['type'] == "open" && $key['level'] == 4) {
174
+ $code[] = $key['attributes']['METHOD'];
175
+ }
176
+ if($key['tag'] == "SERVICE" && $key['type'] == "complete" && $key['level'] == 5) {
177
+ $method[] = $key['value'];
178
+ }
179
+ if($key['tag'] == "COST" && $key['type'] == "complete" && $key['level'] == 5) {
180
+ $cost[] = $key['value'];
181
+ }
182
+ }
183
+
184
+ $la = count($code);
185
+ $lb = count($method);
186
+ $lc = count($cost);
187
+
188
+ if($la = $lb = $lc){
189
+ foreach($code as $index => $value){
190
+ if (in_array($value, $supportedServices)) {
191
+ $rateResult[] = array("code" => $code[$index],
192
+ "title" => $method[$index],
193
+ "amount" =>$cost[$index]) ;
194
+ }
195
+ }
196
+ }
197
+ return $rateResult;
198
+
199
+ }
200
+
201
+ protected function _formatResponse($response) {
202
+ $values = array();
203
+ $index = array();
204
+
205
+ $p = xml_parser_create();
206
+ xml_parse_into_struct($p, $response->getBody(), $values, $index);
207
+ xml_parser_free($p);
208
+
209
+ //print_r($values);
210
+ //print_r($index);
211
+ $exceptions = array();
212
+ $warnings = array();
213
+ }
214
+
215
+ }
package.xml CHANGED
@@ -1,18 +1,21 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mage_Shipwire</name>
4
- <version>1.2.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Shipwire Extension</summary>
10
  <description>Shipwire Rating API shipping method</description>
11
- <notes>Shipwire Shipping Rating API integrated</notes>
 
 
 
12
  <authors><author><name>Shipwire</name><user>auto-converted</user><email>magento-dev@shipwire.com</email></author></authors>
13
- <date>2010-12-17</date>
14
- <time>00:06:52</time>
15
- <contents><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Shipwire_Shipping.xml" hash="89ae766499a54d75ac436f50efc2496c"/></dir></dir></dir></target><target name="magelocal"><dir name="Shipwire"><dir name="Shipping"><dir name="etc"><file name="config.xml" hash="1f073aae242b24b08032b22abf6c98c4"/><file name="system.xml" hash="0e5b1aafaa66a8d9a855078c76906568"/></dir><dir name="Model"><dir name="Carrier"><file name="Service.php" hash="aaceaced3d084b1130dc7d97c22ba140"/><file name="ShippingMethod.php" hash="38790354ca0e9f76b0e3e38620cc76e9"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies/>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mage_Shipwire</name>
4
+ <version>1.2.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Shipwire Extension</summary>
10
  <description>Shipwire Rating API shipping method</description>
11
+ <notes>Shipwire Shipping Rating API integrated
12
+
13
+ 1.2.1
14
+ - Fixed issue with ship-to postcode not passing</notes>
15
  <authors><author><name>Shipwire</name><user>auto-converted</user><email>magento-dev@shipwire.com</email></author></authors>
16
+ <date>2011-01-06</date>
17
+ <time>04:30:31</time>
18
+ <contents><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Shipwire_Shipping.xml" hash="89ae766499a54d75ac436f50efc2496c"/></dir></dir></dir></target><target name="magelocal"><dir name="Shipwire"><dir name="Shipping"><dir name="etc"><file name="config.xml" hash="1f073aae242b24b08032b22abf6c98c4"/><file name="system.xml" hash="0e5b1aafaa66a8d9a855078c76906568"/></dir><dir name="Model"><dir name="Carrier"><file name="Service.php" hash="aaceaced3d084b1130dc7d97c22ba140"/><file name="ShippingMethod.php" hash="9efb7e519cc345b4caf1d65ccc00a4d2"/></dir></dir></dir></dir></target></contents>
19
  <compatible/>
20
  <dependencies/>
21
  </package>