@@ -455,7 +455,7 @@ protected function _getCgiQuotes()
455
455
{
456
456
$ rowRequest = $ this ->_rawRequest ;
457
457
if (self ::USA_COUNTRY_ID == $ rowRequest ->getDestCountry ()) {
458
- $ destPostal = substr ($ rowRequest ->getDestPostal (), 0 , 5 );
458
+ $ destPostal = substr (( string ) $ rowRequest ->getDestPostal (), 0 , 5 );
459
459
} else {
460
460
$ destPostal = $ rowRequest ->getDestPostal ();
461
461
}
@@ -613,7 +613,7 @@ protected function _getXmlQuotes()
613
613
614
614
$ rowRequest = $ this ->_rawRequest ;
615
615
if (self ::USA_COUNTRY_ID == $ rowRequest ->getDestCountry ()) {
616
- $ destPostal = substr ($ rowRequest ->getDestPostal (), 0 , 5 );
616
+ $ destPostal = substr (( string ) $ rowRequest ->getDestPostal (), 0 , 5 );
617
617
} else {
618
618
$ destPostal = $ rowRequest ->getDestPostal ();
619
619
}
@@ -833,76 +833,15 @@ protected function _parseXmlResponse($xmlResponse)
833
833
834
834
$ allowedCurrencies = $ this ->_currencyFactory ->create ()->getConfigAllowCurrencies ();
835
835
foreach ($ arr as $ shipElement ) {
836
- $ code = (string )$ shipElement ->Service ->Code ;
837
- if (in_array ($ code , $ allowedMethods )) {
838
- //The location of tax information is in a different place
839
- // depending on whether we are using negotiated rates or not
840
- if ($ negotiatedActive ) {
841
- $ includeTaxesArr = $ xml ->getXpath (
842
- "//RatingServiceSelectionResponse/RatedShipment/NegotiatedRates "
843
- . "/NetSummaryCharges/TotalChargesWithTaxes "
844
- );
845
- $ includeTaxesActive = $ this ->getConfigFlag ('include_taxes ' ) && !empty ($ includeTaxesArr );
846
- if ($ includeTaxesActive ) {
847
- $ cost = $ shipElement ->NegotiatedRates
848
- ->NetSummaryCharges
849
- ->TotalChargesWithTaxes
850
- ->MonetaryValue ;
851
-
852
- $ responseCurrencyCode = $ this ->mapCurrencyCode (
853
- (string )$ shipElement ->NegotiatedRates
854
- ->NetSummaryCharges
855
- ->TotalChargesWithTaxes
856
- ->CurrencyCode
857
- );
858
- } else {
859
- $ cost = $ shipElement ->NegotiatedRates ->NetSummaryCharges ->GrandTotal ->MonetaryValue ;
860
- $ responseCurrencyCode = $ this ->mapCurrencyCode (
861
- (string )$ shipElement ->NegotiatedRates ->NetSummaryCharges ->GrandTotal ->CurrencyCode
862
- );
863
- }
864
- } else {
865
- $ includeTaxesArr = $ xml ->getXpath (
866
- "//RatingServiceSelectionResponse/RatedShipment/TotalChargesWithTaxes "
867
- );
868
- $ includeTaxesActive = $ this ->getConfigFlag ('include_taxes ' ) && !empty ($ includeTaxesArr );
869
- if ($ includeTaxesActive ) {
870
- $ cost = $ shipElement ->TotalChargesWithTaxes ->MonetaryValue ;
871
- $ responseCurrencyCode = $ this ->mapCurrencyCode (
872
- (string )$ shipElement ->TotalChargesWithTaxes ->CurrencyCode
873
- );
874
- } else {
875
- $ cost = $ shipElement ->TotalCharges ->MonetaryValue ;
876
- $ responseCurrencyCode = $ this ->mapCurrencyCode (
877
- (string )$ shipElement ->TotalCharges ->CurrencyCode
878
- );
879
- }
880
- }
881
-
882
- //convert price with Origin country currency code to base currency code
883
- $ successConversion = true ;
884
- if ($ responseCurrencyCode ) {
885
- if (in_array ($ responseCurrencyCode , $ allowedCurrencies )) {
886
- $ cost = (double )$ cost * $ this ->_getBaseCurrencyRate ($ responseCurrencyCode );
887
- } else {
888
- $ errorTitle = __ (
889
- 'We can \'t convert a rate from "%1-%2". ' ,
890
- $ responseCurrencyCode ,
891
- $ this ->_request ->getPackageCurrency ()->getCode ()
892
- );
893
- $ error = $ this ->_rateErrorFactory ->create ();
894
- $ error ->setCarrier ('ups ' );
895
- $ error ->setCarrierTitle ($ this ->getConfigData ('title ' ));
896
- $ error ->setErrorMessage ($ errorTitle );
897
- $ successConversion = false ;
898
- }
899
- }
900
-
901
- if ($ successConversion ) {
902
- $ costArr [$ code ] = $ cost ;
903
- $ priceArr [$ code ] = $ this ->getMethodPrice ((float )$ cost , $ code );
904
- }
905
- }
836
+ $ this ->processShippingRateForItem (
837
+ $ shipElement ,
838
+ $ allowedMethods ,
839
+ $ allowedCurrencies ,
840
+ $ costArr ,
841
+ $ priceArr ,
842
+ $ negotiatedActive ,
843
+ $ xml
844
+ );
906
845
}
907
846
} else {
908
847
$ arr = $ xml ->getXpath ("//RatingServiceSelectionResponse/Response/Error/ErrorDescription/text() " );
@@ -945,6 +884,99 @@ protected function _parseXmlResponse($xmlResponse)
945
884
return $ result ;
946
885
}
947
886
887
+ /**
888
+ * Processing rate for ship element
889
+ *
890
+ * @param \Magento\Framework\Simplexml\Element $shipElement
891
+ * @param array $allowedMethods
892
+ * @param array $allowedCurrencies
893
+ * @param array $costArr
894
+ * @param array $priceArr
895
+ * @param bool $negotiatedActive
896
+ * @param \Magento\Framework\Simplexml\Config $xml
897
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
898
+ */
899
+ private function processShippingRateForItem (
900
+ \Magento \Framework \Simplexml \Element $ shipElement ,
901
+ array $ allowedMethods ,
902
+ array $ allowedCurrencies ,
903
+ array &$ costArr ,
904
+ array &$ priceArr ,
905
+ bool $ negotiatedActive ,
906
+ \Magento \Framework \Simplexml \Config $ xml
907
+ ): void {
908
+ $ code = (string )$ shipElement ->Service ->Code ;
909
+ if (in_array ($ code , $ allowedMethods )) {
910
+ //The location of tax information is in a different place
911
+ // depending on whether we are using negotiated rates or not
912
+ if ($ negotiatedActive ) {
913
+ $ includeTaxesArr = $ xml ->getXpath (
914
+ "//RatingServiceSelectionResponse/RatedShipment/NegotiatedRates "
915
+ . "/NetSummaryCharges/TotalChargesWithTaxes "
916
+ );
917
+ $ includeTaxesActive = $ this ->getConfigFlag ('include_taxes ' ) && !empty ($ includeTaxesArr );
918
+ if ($ includeTaxesActive ) {
919
+ $ cost = $ shipElement ->NegotiatedRates
920
+ ->NetSummaryCharges
921
+ ->TotalChargesWithTaxes
922
+ ->MonetaryValue ;
923
+
924
+ $ responseCurrencyCode = $ this ->mapCurrencyCode (
925
+ (string )$ shipElement ->NegotiatedRates
926
+ ->NetSummaryCharges
927
+ ->TotalChargesWithTaxes
928
+ ->CurrencyCode
929
+ );
930
+ } else {
931
+ $ cost = $ shipElement ->NegotiatedRates ->NetSummaryCharges ->GrandTotal ->MonetaryValue ;
932
+ $ responseCurrencyCode = $ this ->mapCurrencyCode (
933
+ (string )$ shipElement ->NegotiatedRates ->NetSummaryCharges ->GrandTotal ->CurrencyCode
934
+ );
935
+ }
936
+ } else {
937
+ $ includeTaxesArr = $ xml ->getXpath (
938
+ "//RatingServiceSelectionResponse/RatedShipment/TotalChargesWithTaxes "
939
+ );
940
+ $ includeTaxesActive = $ this ->getConfigFlag ('include_taxes ' ) && !empty ($ includeTaxesArr );
941
+ if ($ includeTaxesActive ) {
942
+ $ cost = $ shipElement ->TotalChargesWithTaxes ->MonetaryValue ;
943
+ $ responseCurrencyCode = $ this ->mapCurrencyCode (
944
+ (string )$ shipElement ->TotalChargesWithTaxes ->CurrencyCode
945
+ );
946
+ } else {
947
+ $ cost = $ shipElement ->TotalCharges ->MonetaryValue ;
948
+ $ responseCurrencyCode = $ this ->mapCurrencyCode (
949
+ (string )$ shipElement ->TotalCharges ->CurrencyCode
950
+ );
951
+ }
952
+ }
953
+
954
+ //convert price with Origin country currency code to base currency code
955
+ $ successConversion = true ;
956
+ if ($ responseCurrencyCode ) {
957
+ if (in_array ($ responseCurrencyCode , $ allowedCurrencies )) {
958
+ $ cost = (double )$ cost * $ this ->_getBaseCurrencyRate ($ responseCurrencyCode );
959
+ } else {
960
+ $ errorTitle = __ (
961
+ 'We can \'t convert a rate from "%1-%2". ' ,
962
+ $ responseCurrencyCode ,
963
+ $ this ->_request ->getPackageCurrency ()->getCode ()
964
+ );
965
+ $ error = $ this ->_rateErrorFactory ->create ();
966
+ $ error ->setCarrier ('ups ' );
967
+ $ error ->setCarrierTitle ($ this ->getConfigData ('title ' ));
968
+ $ error ->setErrorMessage ($ errorTitle );
969
+ $ successConversion = false ;
970
+ }
971
+ }
972
+
973
+ if ($ successConversion ) {
974
+ $ costArr [$ code ] = $ cost ;
975
+ $ priceArr [$ code ] = $ this ->getMethodPrice ((float )$ cost , $ code );
976
+ }
977
+ }
978
+ }
979
+
948
980
/**
949
981
* Get tracking
950
982
*
@@ -1101,54 +1133,7 @@ protected function _parseXmlTrackingResponse($trackingValue, $xmlResponse)
1101
1133
if ($ activityTags ) {
1102
1134
$ index = 1 ;
1103
1135
foreach ($ activityTags as $ activityTag ) {
1104
- $ addressArr = [];
1105
- if (isset ($ activityTag ->ActivityLocation ->Address ->City )) {
1106
- $ addressArr [] = (string )$ activityTag ->ActivityLocation ->Address ->City ;
1107
- }
1108
- if (isset ($ activityTag ->ActivityLocation ->Address ->StateProvinceCode )) {
1109
- $ addressArr [] = (string )$ activityTag ->ActivityLocation ->Address ->StateProvinceCode ;
1110
- }
1111
- if (isset ($ activityTag ->ActivityLocation ->Address ->CountryCode )) {
1112
- $ addressArr [] = (string )$ activityTag ->ActivityLocation ->Address ->CountryCode ;
1113
- }
1114
- $ dateArr = [];
1115
- $ date = (string )$ activityTag ->Date ;
1116
- //YYYYMMDD
1117
- $ dateArr [] = substr ($ date , 0 , 4 );
1118
- $ dateArr [] = substr ($ date , 4 , 2 );
1119
- $ dateArr [] = substr ($ date , -2 , 2 );
1120
-
1121
- $ timeArr = [];
1122
- $ time = (string )$ activityTag ->Time ;
1123
- //HHMMSS
1124
- $ timeArr [] = substr ($ time , 0 , 2 );
1125
- $ timeArr [] = substr ($ time , 2 , 2 );
1126
- $ timeArr [] = substr ($ time , -2 , 2 );
1127
-
1128
- if ($ index === 1 ) {
1129
- $ resultArr ['status ' ] = (string )$ activityTag ->Status ->StatusType ->Description ;
1130
- $ resultArr ['deliverydate ' ] = implode ('- ' , $ dateArr );
1131
- //YYYY-MM-DD
1132
- $ resultArr ['deliverytime ' ] = implode (': ' , $ timeArr );
1133
- //HH:MM:SS
1134
- $ resultArr ['deliverylocation ' ] = (string )$ activityTag ->ActivityLocation ->Description ;
1135
- $ resultArr ['signedby ' ] = (string )$ activityTag ->ActivityLocation ->SignedForByName ;
1136
- if ($ addressArr ) {
1137
- $ resultArr ['deliveryto ' ] = implode (', ' , $ addressArr );
1138
- }
1139
- } else {
1140
- $ tempArr = [];
1141
- $ tempArr ['activity ' ] = (string )$ activityTag ->Status ->StatusType ->Description ;
1142
- $ tempArr ['deliverydate ' ] = implode ('- ' , $ dateArr );
1143
- //YYYY-MM-DD
1144
- $ tempArr ['deliverytime ' ] = implode (': ' , $ timeArr );
1145
- //HH:MM:SS
1146
- if ($ addressArr ) {
1147
- $ tempArr ['deliverylocation ' ] = implode (', ' , $ addressArr );
1148
- }
1149
- $ packageProgress [] = $ tempArr ;
1150
- }
1151
- $ index ++;
1136
+ $ this ->processActivityTagInfo ($ activityTag , $ index , $ resultArr , $ packageProgress );
1152
1137
}
1153
1138
$ resultArr ['progressdetail ' ] = $ packageProgress ;
1154
1139
}
@@ -1181,6 +1166,70 @@ protected function _parseXmlTrackingResponse($trackingValue, $xmlResponse)
1181
1166
return $ this ->_result ;
1182
1167
}
1183
1168
1169
+ /**
1170
+ * Process tracking info from activity tag
1171
+ *
1172
+ * @param \Magento\Framework\Simplexml\Element $activityTag
1173
+ * @param int $index
1174
+ * @param array $resultArr
1175
+ * @param array $packageProgress
1176
+ */
1177
+ private function processActivityTagInfo (
1178
+ \Magento \Framework \Simplexml \Element $ activityTag ,
1179
+ int &$ index ,
1180
+ array &$ resultArr ,
1181
+ array &$ packageProgress
1182
+ ) {
1183
+ $ addressArr = [];
1184
+ if (isset ($ activityTag ->ActivityLocation ->Address ->City )) {
1185
+ $ addressArr [] = (string )$ activityTag ->ActivityLocation ->Address ->City ;
1186
+ }
1187
+ if (isset ($ activityTag ->ActivityLocation ->Address ->StateProvinceCode )) {
1188
+ $ addressArr [] = (string )$ activityTag ->ActivityLocation ->Address ->StateProvinceCode ;
1189
+ }
1190
+ if (isset ($ activityTag ->ActivityLocation ->Address ->CountryCode )) {
1191
+ $ addressArr [] = (string )$ activityTag ->ActivityLocation ->Address ->CountryCode ;
1192
+ }
1193
+ $ dateArr = [];
1194
+ $ date = (string )$ activityTag ->Date ;
1195
+ //YYYYMMDD
1196
+ $ dateArr [] = substr ($ date , 0 , 4 );
1197
+ $ dateArr [] = substr ($ date , 4 , 2 );
1198
+ $ dateArr [] = substr ($ date , -2 , 2 );
1199
+
1200
+ $ timeArr = [];
1201
+ $ time = (string )$ activityTag ->Time ;
1202
+ //HHMMSS
1203
+ $ timeArr [] = substr ($ time , 0 , 2 );
1204
+ $ timeArr [] = substr ($ time , 2 , 2 );
1205
+ $ timeArr [] = substr ($ time , -2 , 2 );
1206
+
1207
+ if ($ index === 1 ) {
1208
+ $ resultArr ['status ' ] = (string )$ activityTag ->Status ->StatusType ->Description ;
1209
+ $ resultArr ['deliverydate ' ] = implode ('- ' , $ dateArr );
1210
+ //YYYY-MM-DD
1211
+ $ resultArr ['deliverytime ' ] = implode (': ' , $ timeArr );
1212
+ //HH:MM:SS
1213
+ $ resultArr ['deliverylocation ' ] = (string )$ activityTag ->ActivityLocation ->Description ;
1214
+ $ resultArr ['signedby ' ] = (string )$ activityTag ->ActivityLocation ->SignedForByName ;
1215
+ if ($ addressArr ) {
1216
+ $ resultArr ['deliveryto ' ] = implode (', ' , $ addressArr );
1217
+ }
1218
+ } else {
1219
+ $ tempArr = [];
1220
+ $ tempArr ['activity ' ] = (string )$ activityTag ->Status ->StatusType ->Description ;
1221
+ $ tempArr ['deliverydate ' ] = implode ('- ' , $ dateArr );
1222
+ //YYYY-MM-DD
1223
+ $ tempArr ['deliverytime ' ] = implode (': ' , $ timeArr );
1224
+ //HH:MM:SS
1225
+ if ($ addressArr ) {
1226
+ $ tempArr ['deliverylocation ' ] = implode (', ' , $ addressArr );
1227
+ }
1228
+ $ packageProgress [] = $ tempArr ;
1229
+ }
1230
+ $ index ++;
1231
+ }
1232
+
1184
1233
/**
1185
1234
* Get tracking response
1186
1235
*
0 commit comments