@@ -730,12 +730,7 @@ protected function _getAllItems()
730
730
$ itemWeight = $ this ->_getWeight ($ itemWeight * $ item ->getQty ());
731
731
$ maxWeight = $ this ->_getWeight ($ this ->_maxWeight , true );
732
732
if ($ itemWeight > $ maxWeight ) {
733
- $ qtyItem = floor ($ itemWeight / $ maxWeight );
734
- $ decimalItems [] = ['weight ' => $ maxWeight , 'qty ' => $ qtyItem ];
735
- $ weightItem = $ this ->mathDivision ->getExactDivision ($ itemWeight , $ maxWeight );
736
- if ($ weightItem ) {
737
- $ decimalItems [] = ['weight ' => $ weightItem , 'qty ' => 1 ];
738
- }
733
+ $ this ->pushDecimalItems ($ decimalItems , $ itemWeight , $ maxWeight );
739
734
$ checkWeight = false ;
740
735
}
741
736
}
@@ -772,6 +767,23 @@ protected function _getAllItems()
772
767
return $ fullItems ;
773
768
}
774
769
770
+ /**
771
+ * Pushes items into array that are decimal places on item weight
772
+ *
773
+ * @param array $decimalItems
774
+ * @param float $itemWeight
775
+ * @param float $maxWeight
776
+ */
777
+ private function pushDecimalItems (array &$ decimalItems , float $ itemWeight , float $ maxWeight ): void
778
+ {
779
+ $ qtyItem = floor ($ itemWeight / $ maxWeight );
780
+ $ decimalItems [] = ['weight ' => $ maxWeight , 'qty ' => $ qtyItem ];
781
+ $ weightItem = $ this ->mathDivision ->getExactDivision ($ itemWeight , $ maxWeight );
782
+ if ($ weightItem ) {
783
+ $ decimalItems [] = ['weight ' => $ weightItem , 'qty ' => 1 ];
784
+ }
785
+ }
786
+
775
787
/**
776
788
* Make pieces
777
789
*
@@ -957,7 +969,7 @@ protected function _getQuotes()
957
969
protected function _getQuotesFromServer ($ request )
958
970
{
959
971
$ client = $ this ->_httpClientFactory ->create ();
960
- $ client ->setUri (( string ) $ this ->getConfigData ( ' gateway_url ' ));
972
+ $ client ->setUri ($ this ->getGatewayURL ( ));
961
973
$ client ->setConfig (['maxredirects ' => 0 , 'timeout ' => 30 ]);
962
974
$ client ->setRawData (utf8_encode ($ request ));
963
975
@@ -1558,7 +1570,7 @@ protected function _doRequest()
1558
1570
$ debugData = ['request ' => $ request ];
1559
1571
try {
1560
1572
$ client = $ this ->_httpClientFactory ->create ();
1561
- $ client ->setUri (( string ) $ this ->getConfigData ( ' gateway_url ' ));
1573
+ $ client ->setUri ($ this ->getGatewayURL ( ));
1562
1574
$ client ->setConfig (['maxredirects ' => 0 , 'timeout ' => 30 ]);
1563
1575
$ client ->setRawData ($ request );
1564
1576
$ responseBody = $ client ->request (\Magento \Framework \HTTP \ZendClient::POST )->getBody ();
@@ -1751,7 +1763,7 @@ protected function _getXMLTracking($trackings)
1751
1763
$ debugData = ['request ' => $ request ];
1752
1764
try {
1753
1765
$ client = new \Magento \Framework \HTTP \ZendClient ();
1754
- $ client ->setUri (( string ) $ this ->getConfigData ( ' gateway_url ' ));
1766
+ $ client ->setUri ($ this ->getGatewayURL ( ));
1755
1767
$ client ->setConfig (['maxredirects ' => 0 , 'timeout ' => 30 ]);
1756
1768
$ client ->setRawData ($ request );
1757
1769
$ responseBody = $ client ->request (\Magento \Framework \HTTP \ZendClient::POST )->getBody ();
@@ -1959,6 +1971,8 @@ protected function _prepareShippingLabelContent(\SimpleXMLElement $xml)
1959
1971
}
1960
1972
1961
1973
/**
1974
+ * Verify if the shipment is dutiable
1975
+ *
1962
1976
* @param string $origCountryId
1963
1977
* @param string $destCountryId
1964
1978
*
@@ -1972,4 +1986,18 @@ protected function isDutiable($origCountryId, $destCountryId)
1972
1986
self ::DHL_CONTENT_TYPE_NON_DOC == $ this ->getConfigData ('content_type ' )
1973
1987
&& !$ this ->_isDomestic ;
1974
1988
}
1989
+
1990
+ /**
1991
+ * Get the gateway URL
1992
+ *
1993
+ * @return string
1994
+ */
1995
+ private function getGatewayURL ()
1996
+ {
1997
+ if ($ this ->getConfigData ('sandbox_mode ' )) {
1998
+ return (string )$ this ->getConfigData ('sandbox_url ' );
1999
+ } else {
2000
+ return (string )$ this ->getConfigData ('gateway_url ' );
2001
+ }
2002
+ }
1975
2003
}
0 commit comments