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->
|
| 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 |
-
<
|
| 113 |
-
|
| 114 |
-
<
|
| 115 |
-
|
| 116 |
-
<
|
| 117 |
-
<
|
| 118 |
-
<
|
| 119 |
-
<
|
| 120 |
-
<
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
curl_setopt($session,
|
| 133 |
-
curl_setopt($session,
|
| 134 |
-
curl_setopt($session,
|
| 135 |
-
curl_setopt($session,
|
| 136 |
-
curl_setopt($session,
|
| 137 |
-
curl_setopt($session,
|
| 138 |
-
curl_setopt($session,
|
| 139 |
-
$
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
$client
|
| 143 |
-
$client->
|
| 144 |
-
$
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
$
|
| 168 |
-
$
|
| 169 |
-
$
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
$
|
| 185 |
-
$
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
"
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
$
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
//print_r($
|
| 210 |
-
$
|
| 211 |
-
$
|
| 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.
|
| 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 |
<authors><author><name>Shipwire</name><user>auto-converted</user><email>magento-dev@shipwire.com</email></author></authors>
|
| 13 |
-
<date>
|
| 14 |
-
<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="
|
| 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>
|
