Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Carrier Class Reference
Inheritance diagram for Carrier:
AbstractCarrierOnline CarrierInterface AbstractCarrier DataObject AbstractCarrierInterface

Public Member Functions

 __construct (\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory, \Psr\Log\LoggerInterface $logger, Security $xmlSecurity, \Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory, \Magento\Shipping\Model\Rate\ResultFactory $rateFactory, \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory, \Magento\Shipping\Model\Tracking\ResultFactory $trackFactory, \Magento\Shipping\Model\Tracking\Result\ErrorFactory $trackErrorFactory, \Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Directory\Helper\Data $directoryData, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, \Magento\Framework\Locale\FormatInterface $localeFormat, Config $configHelper, ClientFactory $httpClientFactory, array $data=[])
 
 collectRates (RateRequest $request)
 
 setRequest (RateRequest $request)
 
 getResult ()
 
 getShipmentByCode ($code, $origin=null)
 
 getTracking ($trackings)
 
 getResponse ()
 
 getAllowedMethods ()
 
 getShipAcceptUrl ()
 
 getShipConfirmUrl ()
 
 getContainerTypes (\Magento\Framework\DataObject $params=null)
 
 getContainerTypesAll ()
 
 getContainerTypesFilter ()
 
 getDeliveryConfirmationTypes (\Magento\Framework\DataObject $params=null)
 
 getCustomizableContainerTypes ()
 
- Public Member Functions inherited from AbstractCarrierOnline
 __construct (\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory, \Psr\Log\LoggerInterface $logger, Security $xmlSecurity, \Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory, \Magento\Shipping\Model\Rate\ResultFactory $rateFactory, \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory, \Magento\Shipping\Model\Tracking\ResultFactory $trackFactory, \Magento\Shipping\Model\Tracking\Result\ErrorFactory $trackErrorFactory, \Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Directory\Helper\Data $directoryData, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, array $data=[])
 
 setActiveFlag ($code='active')
 
 getCarrierCode ()
 
 getTrackingInfo ($tracking)
 
 isTrackingAvailable ()
 
 isCityRequired ()
 
 isZipCodeRequired ($countryId=null)
 
 isShippingLabelsAvailable ()
 
 getAllItems (RateRequest $request)
 
 proccessAdditionalValidation (\Magento\Framework\DataObject $request)
 
 requestToShipment ($request)
 
 returnOfShipment ($request)
 
 rollBack ($data)
 
 isGirthAllowed ($countyDest=null, $carrierMethodCode=null)
 
 setRawRequest ($request)
 
 getMethodPrice ($cost, $method='')
 
 parseXml ($xmlContent, $customSimplexml='SimpleXMLElement')
 
 canCollectRates ()
 
- Public Member Functions inherited from AbstractCarrier
 __construct (\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory, \Psr\Log\LoggerInterface $logger, array $data=[])
 
 getConfigData ($field)
 
 getConfigFlag ($field)
 
 requestToShipment ($request)
 
 returnOfShipment ($request)
 
 getContainerTypes (\Magento\Framework\DataObject $params=null)
 
 getCustomizableContainerTypes ()
 
 getDeliveryConfirmationTypes (\Magento\Framework\DataObject $params=null)
 
 processAdditionalValidation (\Magento\Framework\DataObject $request)
 
 proccessAdditionalValidation (\Magento\Framework\DataObject $request)
 
 isActive ()
 
 isFixed ()
 
 isTrackingAvailable ()
 
 isShippingLabelsAvailable ()
 
 getSortOrder ()
 
 getFinalPriceWithHandlingFee ($cost)
 
 getTotalNumOfBoxes ($weight)
 
 isStateProvinceRequired ()
 
 isCityRequired ()
 
 isZipCodeRequired ($countryId=null)
 
 getDebugFlag ()
 
 debugData ($debugData)
 
 getCarrierCode ()
 
 getContentTypes (\Magento\Framework\DataObject $params)
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from AbstractCarrierInterface
 checkAvailableShipCountries (\Magento\Framework\DataObject $request)
 
- Public Member Functions inherited from CarrierInterface
 isTrackingAvailable ()
 

Data Fields

const CODE = 'ups'
 
const DELIVERY_CONFIRMATION_SHIPMENT = 1
 
const DELIVERY_CONFIRMATION_PACKAGE = 2
 
- Data Fields inherited from AbstractCarrierOnline
const USA_COUNTRY_ID = 'US'
 
const PUERTORICO_COUNTRY_ID = 'PR'
 
const GUAM_COUNTRY_ID = 'GU'
 
const GUAM_REGION_CODE = 'GU'
 
- Data Fields inherited from AbstractCarrier
const DEBUG_KEYS_MASK = '****'
 
const USA_COUNTRY_ID = 'US'
 
const CANADA_COUNTRY_ID = 'CA'
 
const MEXICO_COUNTRY_ID = 'MX'
 
const HANDLING_TYPE_PERCENT = 'P'
 
const HANDLING_TYPE_FIXED = 'F'
 
const HANDLING_ACTION_PERPACKAGE = 'P'
 
const HANDLING_ACTION_PERORDER = 'O'
 

Protected Member Functions

 _getCorrectWeight ($weight)
 
 _getQuotes ()
 
 _setFreeMethodRequest ($freeMethod)
 
 _getCgiQuotes ()
 
 _parseCgiResponse ($response)
 
 _getXmlQuotes ()
 
 _getBaseCurrencyRate ($code)
 
 _parseXmlResponse ($xmlResponse)
 
 setXMLAccessRequest ()
 
 _getCgiTracking ($trackings)
 
 _getXmlTracking ($trackings)
 
 _parseXmlTrackingResponse ($trackingValue, $xmlResponse)
 
 _sendShipmentAcceptRequest (Element $shipmentConfirmResponse)
 
 _doShipmentRequest (\Magento\Framework\DataObject $request)
 
 _getDeliveryConfirmationLevel ($countyDestination=null)
 
- Protected Member Functions inherited from AbstractCarrierOnline
 _getQuotesCacheKey ($requestParams)
 
 _getCachedQuotes ($requestParams)
 
 _setCachedQuotes ($requestParams, $response)
 
 _prepareServiceName ($name)
 
 _prepareShipmentRequest (\Magento\Framework\DataObject $request)
 
 _doShipmentRequest (\Magento\Framework\DataObject $request)
 
 _isUSCountry ($countyId)
 
 debugErrors ($errors)
 
 getErrorMessage ()
 
- Protected Member Functions inherited from AbstractCarrier
 _getAllowedContainers (\Magento\Framework\DataObject $params=null)
 
 _updateFreeMethodQuote ($request)
 
 _getPerpackagePrice ($cost, $handlingType, $handlingFee)
 
 _getPerorderPrice ($cost, $handlingType, $handlingFee)
 
 _debug ($debugData)
 
 filterDebugData ($data)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_code = self::CODE
 
 $_request
 
 $_result
 
 $_baseCurrencyRate
 
 $_xmlAccessRequest
 
 $_defaultCgiGatewayUrl = 'http://www.ups.com:80/using/services/rave/qcostcgi.cgi'
 
 $_defaultUrls
 
 $_liveUrls
 
 $_customizableContainerTypes = ['CP', 'CSP']
 
 $_localeFormat
 
 $_logger
 
 $configHelper
 
 $_debugReplacePrivateDataKeys
 
- Protected Attributes inherited from AbstractCarrierOnline
 $_activeFlag = 'active'
 
 $_directoryData = null
 
 $_xmlElFactory
 
 $_rateFactory
 
 $_rateMethodFactory
 
 $_trackFactory
 
 $_trackErrorFactory
 
 $_trackStatusFactory
 
 $_regionFactory
 
 $_countryFactory
 
 $_currencyFactory
 
 $stockRegistry
 
 $_rawRequest = null
 
 $xmlSecurity
 
- Protected Attributes inherited from AbstractCarrier
 $_code
 
 $_rates
 
 $_numBoxes = 1
 
 $_freeMethod = 'free_method'
 
 $_isFixed = false
 
 $_customizableContainerTypes = []
 
 $_debugReplacePrivateDataKeys = []
 
 $_scopeConfig
 
 $_rateErrorFactory
 
 $_logger
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from AbstractCarrierOnline
static $_quotesCache = []
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

UPS shipping implementation @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 24 of file Carrier.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Config\ScopeConfigInterface  $scopeConfig,
\Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory  $rateErrorFactory,
\Psr\Log\LoggerInterface  $logger,
Security  $xmlSecurity,
\Magento\Shipping\Model\Simplexml\ElementFactory  $xmlElFactory,
\Magento\Shipping\Model\Rate\ResultFactory  $rateFactory,
\Magento\Quote\Model\Quote\Address\RateResult\MethodFactory  $rateMethodFactory,
\Magento\Shipping\Model\Tracking\ResultFactory  $trackFactory,
\Magento\Shipping\Model\Tracking\Result\ErrorFactory  $trackErrorFactory,
\Magento\Shipping\Model\Tracking\Result\StatusFactory  $trackStatusFactory,
\Magento\Directory\Model\RegionFactory  $regionFactory,
\Magento\Directory\Model\CountryFactory  $countryFactory,
\Magento\Directory\Model\CurrencyFactory  $currencyFactory,
\Magento\Directory\Helper\Data  $directoryData,
\Magento\CatalogInventory\Api\StockRegistryInterface  $stockRegistry,
\Magento\Framework\Locale\FormatInterface  $localeFormat,
Config  $configHelper,
ClientFactory  $httpClientFactory,
array  $data = [] 
)
Parameters
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig
\Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory$rateErrorFactory
\Psr\Log\LoggerInterface$logger
Security$xmlSecurity
\Magento\Shipping\Model\Simplexml\ElementFactory$xmlElFactory
\Magento\Shipping\Model\Rate\ResultFactory$rateFactory
\Magento\Quote\Model\Quote\Address\RateResult\MethodFactory$rateMethodFactory
\Magento\Shipping\Model\Tracking\ResultFactory$trackFactory
\Magento\Shipping\Model\Tracking\Result\ErrorFactory$trackErrorFactory
\Magento\Shipping\Model\Tracking\Result\StatusFactory$trackStatusFactory
\Magento\Directory\Model\RegionFactory$regionFactory
\Magento\Directory\Model\CountryFactory$countryFactory
\Magento\Directory\Model\CurrencyFactory$currencyFactory
\Magento\Directory\Helper\Data$directoryData
\Magento\CatalogInventory\Api\StockRegistryInterface$stockRegistry
\Magento\Framework\Locale\FormatInterface$localeFormat
Config$configHelper
ClientFactory$httpClientFactory
array$data@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 159 of file Carrier.php.

179  {
180  parent::__construct(
181  $scopeConfig,
182  $rateErrorFactory,
183  $logger,
184  $xmlSecurity,
185  $xmlElFactory,
186  $rateFactory,
187  $rateMethodFactory,
188  $trackFactory,
189  $trackErrorFactory,
190  $trackStatusFactory,
191  $regionFactory,
192  $countryFactory,
193  $currencyFactory,
194  $directoryData,
196  $data
197  );
198  $this->httpClientFactory = $httpClientFactory;
199  $this->_localeFormat = $localeFormat;
200  $this->configHelper = $configHelper;
201  }
$logger

Member Function Documentation

◆ _doShipmentRequest()

_doShipmentRequest ( \Magento\Framework\DataObject  $request)
protected

Do shipment request to carrier web service, obtain Print Shipping Labels and process errors in response

Parameters
\Magento\Framework\DataObject$request
Returns
\Magento\Framework\DataObject

Definition at line 1504 of file Carrier.php.

1505  {
1507  $result = new \Magento\Framework\DataObject();
1508  $rawXmlRequest = $this->_formShipmentRequest($request);
1509  $this->setXMLAccessRequest();
1510  $xmlRequest = $this->_xmlAccessRequest . $rawXmlRequest;
1511  $xmlResponse = $this->_getCachedQuotes($xmlRequest);
1512 
1513  if ($xmlResponse === null) {
1514  $debugData['request'] = $this->filterDebugData($this->_xmlAccessRequest) . $rawXmlRequest;
1515  $url = $this->getShipConfirmUrl();
1516  $client = $this->httpClientFactory->create();
1517  try {
1518  $client->post($url, $xmlRequest);
1519  $xmlResponse = $client->getBody();
1520  $debugData['result'] = $xmlResponse;
1521  $this->_setCachedQuotes($xmlRequest, $xmlResponse);
1522  } catch (\Throwable $e) {
1523  $debugData['result'] = ['code' => $e->getCode(), 'error' => $e->getMessage()];
1524  }
1525  }
1526 
1527  try {
1528  $response = $this->_xmlElFactory->create(['data' => $xmlResponse]);
1529  } catch (\Throwable $e) {
1530  $debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];
1531  $result->setErrors($e->getMessage());
1532  }
1533 
1534  if (isset($response->Response->Error)
1535  && in_array($response->Response->Error->ErrorSeverity, ['Hard', 'Transient'])
1536  ) {
1537  $result->setErrors((string)$response->Response->Error->ErrorDescription);
1538  }
1539 
1540  $this->_debug($debugData);
1541 
1542  if ($result->hasErrors() || empty($response)) {
1543  return $result;
1544  } else {
1545  return $this->_sendShipmentAcceptRequest($response);
1546  }
1547  }
_prepareShipmentRequest(\Magento\Framework\DataObject $request)
$response
Definition: 404.php:11
_sendShipmentAcceptRequest(Element $shipmentConfirmResponse)
Definition: Carrier.php:1439

◆ _getBaseCurrencyRate()

_getBaseCurrencyRate (   $code)
protected

Get base currency rate

Parameters
string$code
Returns
float

Definition at line 768 of file Carrier.php.

769  {
770  if (!$this->_baseCurrencyRate) {
771  $this->_baseCurrencyRate = $this->_currencyFactory->create()->load(
772  $code
773  )->getAnyRate(
774  $this->_request->getBaseCurrency()->getCode()
775  );
776  }
777 
779  }
$code
Definition: info.phtml:12

◆ _getCgiQuotes()

_getCgiQuotes ( )
protected

Get cgi rates

Returns
Result

Definition at line 445 of file Carrier.php.

446  {
447  $rowRequest = $this->_rawRequest;
448  if (self::USA_COUNTRY_ID == $rowRequest->getDestCountry()) {
449  $destPostal = substr($rowRequest->getDestPostal(), 0, 5);
450  } else {
451  $destPostal = $rowRequest->getDestPostal();
452  }
453 
454  $params = [
455  'accept_UPS_license_agreement' => 'yes',
456  '10_action' => $rowRequest->getAction(),
457  '13_product' => $rowRequest->getProduct(),
458  '14_origCountry' => $rowRequest->getOrigCountry(),
459  '15_origPostal' => $rowRequest->getOrigPostal(),
460  'origCity' => $rowRequest->getOrigCity(),
461  '19_destPostal' => $destPostal,
462  '22_destCountry' => $rowRequest->getDestCountry(),
463  '23_weight' => $rowRequest->getWeight(),
464  '47_rate_chart' => $rowRequest->getPickup(),
465  '48_container' => $rowRequest->getContainer(),
466  '49_residential' => $rowRequest->getDestType(),
467  'weight_std' => strtolower($rowRequest->getUnitMeasure()),
468  ];
469  $params['47_rate_chart'] = $params['47_rate_chart']['label'];
470 
471  $responseBody = $this->_getCachedQuotes($params);
472  if ($responseBody === null) {
473  $debugData = ['request' => $params];
474  try {
475  $url = $this->getConfigData('gateway_url');
476  if (!$url) {
478  }
479  $client = new \Zend_Http_Client();
480  $client->setUri($url);
481  $client->setConfig(['maxredirects' => 0, 'timeout' => 30]);
482  $client->setParameterGet($params);
483  $response = $client->request();
484  $responseBody = $response->getBody();
485 
486  $debugData['result'] = $responseBody;
487  $this->_setCachedQuotes($params, $responseBody);
488  } catch (\Throwable $e) {
489  $debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];
490  $responseBody = '';
491  }
492  $this->_debug($debugData);
493  }
494 
495  return $this->_parseCgiResponse($responseBody);
496  }
$response
Definition: 404.php:11
_parseCgiResponse($response)
Definition: Carrier.php:525
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ _getCgiTracking()

_getCgiTracking (   $trackings)
protected

Get cgi tracking

Parameters
string[]$trackings
Returns
\Magento\Shipping\Model\Tracking\ResultFactory

Definition at line 988 of file Carrier.php.

989  {
990  //ups no longer support tracking for data streaming version
991  //so we can only reply the popup window to ups.
992  $result = $this->_trackFactory->create();
993  foreach ($trackings as $tracking) {
994  $status = $this->_trackStatusFactory->create();
995  $status->setCarrier('ups');
996  $status->setCarrierTitle($this->getConfigData('title'));
997  $status->setTracking($tracking);
998  $status->setPopup(1);
999  $status->setUrl(
1000  "http://wwwapps.ups.com/WebTracking/processInputRequest?HTMLVersion=5.0&error_carried=true" .
1001  "&tracknums_displayed=5&TypeOfInquiryNumber=T&loc=en_US&InquiryNumber1={$tracking}" .
1002  "&AgreeToTermsAndConditions=yes"
1003  );
1004  $result->append($status);
1005  }
1006 
1007  $this->_result = $result;
1008 
1009  return $result;
1010  }
$status
Definition: order_status.php:8

◆ _getCorrectWeight()

_getCorrectWeight (   $weight)
protected

Get correct weight

Namely: Checks the current weight to comply with the minimum weight standards set by the carrier. Then strictly rounds the weight up until the first significant digit after the decimal point.

Parameters
float | int$weight
Returns
float

Definition at line 380 of file Carrier.php.

381  {
382  $minWeight = $this->getConfigData('min_package_weight');
383 
384  if ($weight < $minWeight) {
385  $weight = $minWeight;
386  }
387 
388  //rounds a number to one significant figure
389  $weight = ceil($weight * 10) / 10;
390 
391  return $weight;
392  }

◆ _getDeliveryConfirmationLevel()

_getDeliveryConfirmationLevel (   $countyDestination = null)
protected

Get delivery confirmation level based on origin/destination Return null if delivery confirmation is not acceptable

Parameters
string | null$countyDestination
Returns
int|null

Definition at line 1708 of file Carrier.php.

1709  {
1710  if ($countyDestination === null) {
1711  return null;
1712  }
1713 
1714  if ($countyDestination == self::USA_COUNTRY_ID) {
1716  }
1717 
1719  }
const DELIVERY_CONFIRMATION_PACKAGE
Definition: Carrier.php:38
const DELIVERY_CONFIRMATION_SHIPMENT
Definition: Carrier.php:36

◆ _getQuotes()

_getQuotes ( )
protected

Do remote request for and handle errors

Returns
Result|null

Definition at line 409 of file Carrier.php.

410  {
411  switch ($this->getConfigData('type')) {
412  case 'UPS':
413  return $this->_getCgiQuotes();
414  case 'UPS_XML':
415  return $this->_getXmlQuotes();
416  default:
417  break;
418  }
419 
420  return null;
421  }

◆ _getXmlQuotes()

_getXmlQuotes ( )
protected

Get xml rates

Returns
Result @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity) @SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 597 of file Carrier.php.

598  {
599  $url = $this->getConfigData('gateway_xml_url');
600 
601  $this->setXMLAccessRequest();
602  $xmlRequest = $this->_xmlAccessRequest;
603  $debugData['accessRequest'] = $this->filterDebugData($xmlRequest);
604 
605  $rowRequest = $this->_rawRequest;
606  if (self::USA_COUNTRY_ID == $rowRequest->getDestCountry()) {
607  $destPostal = substr($rowRequest->getDestPostal(), 0, 5);
608  } else {
609  $destPostal = $rowRequest->getDestPostal();
610  }
611  $params = [
612  'accept_UPS_license_agreement' => 'yes',
613  '10_action' => $rowRequest->getAction(),
614  '13_product' => $rowRequest->getProduct(),
615  '14_origCountry' => $rowRequest->getOrigCountry(),
616  '15_origPostal' => $rowRequest->getOrigPostal(),
617  'origCity' => $rowRequest->getOrigCity(),
618  'origRegionCode' => $rowRequest->getOrigRegionCode(),
619  '19_destPostal' => $destPostal,
620  '22_destCountry' => $rowRequest->getDestCountry(),
621  'destRegionCode' => $rowRequest->getDestRegionCode(),
622  '23_weight' => $rowRequest->getWeight(),
623  '47_rate_chart' => $rowRequest->getPickup(),
624  '48_container' => $rowRequest->getContainer(),
625  '49_residential' => $rowRequest->getDestType(),
626  ];
627 
628  if ($params['10_action'] == '4') {
629  $params['10_action'] = 'Shop';
630  $serviceCode = null;
631  } else {
632  $params['10_action'] = 'Rate';
633  $serviceCode = $rowRequest->getProduct() ? $rowRequest->getProduct() : null;
634  }
635  $serviceDescription = $serviceCode ? $this->getShipmentByCode($serviceCode) : '';
636 
637  $xmlParams = <<<XMLRequest
638 <?xml version="1.0"?>
639 <RatingServiceSelectionRequest xml:lang="en-US">
640  <Request>
641  <TransactionReference>
642  <CustomerContext>Rating and Service</CustomerContext>
643  <XpciVersion>1.0</XpciVersion>
644  </TransactionReference>
645  <RequestAction>Rate</RequestAction>
646  <RequestOption>{$params['10_action']}</RequestOption>
647  </Request>
648  <PickupType>
649  <Code>{$params['47_rate_chart']['code']}</Code>
650  <Description>{$params['47_rate_chart']['label']}</Description>
651  </PickupType>
652 
653  <Shipment>
654 XMLRequest;
655 
656  if ($serviceCode !== null) {
657  $xmlParams .= "<Service>" .
658  "<Code>{$serviceCode}</Code>" .
659  "<Description>{$serviceDescription}</Description>" .
660  "</Service>";
661  }
662 
663  $xmlParams .= <<<XMLRequest
664  <Shipper>
665 XMLRequest;
666 
667  if ($this->getConfigFlag('negotiated_active') && ($shipperNumber = $this->getConfigData('shipper_number'))) {
668  $xmlParams .= "<ShipperNumber>{$shipperNumber}</ShipperNumber>";
669  }
670 
671  if ($rowRequest->getIsReturn()) {
672  $shipperCity = '';
673  $shipperPostalCode = $params['19_destPostal'];
674  $shipperCountryCode = $params['22_destCountry'];
675  $shipperStateProvince = $params['destRegionCode'];
676  } else {
677  $shipperCity = $params['origCity'];
678  $shipperPostalCode = $params['15_origPostal'];
679  $shipperCountryCode = $params['14_origCountry'];
680  $shipperStateProvince = $params['origRegionCode'];
681  }
682 
683  $xmlParams .= <<<XMLRequest
684  <Address>
685  <City>{$shipperCity}</City>
686  <PostalCode>{$shipperPostalCode}</PostalCode>
687  <CountryCode>{$shipperCountryCode}</CountryCode>
688  <StateProvinceCode>{$shipperStateProvince}</StateProvinceCode>
689  </Address>
690  </Shipper>
691 
692  <ShipTo>
693  <Address>
694  <PostalCode>{$params['19_destPostal']}</PostalCode>
695  <CountryCode>{$params['22_destCountry']}</CountryCode>
696  <ResidentialAddress>{$params['49_residential']}</ResidentialAddress>
697  <StateProvinceCode>{$params['destRegionCode']}</StateProvinceCode>
698 XMLRequest;
699 
700  if ($params['49_residential'] === '01') {
701  $xmlParams .= "<ResidentialAddressIndicator>{$params['49_residential']}</ResidentialAddressIndicator>";
702  }
703 
704  $xmlParams .= <<<XMLRequest
705  </Address>
706  </ShipTo>
707 
708  <ShipFrom>
709  <Address>
710  <PostalCode>{$params['15_origPostal']}</PostalCode>
711  <CountryCode>{$params['14_origCountry']}</CountryCode>
712  <StateProvinceCode>{$params['origRegionCode']}</StateProvinceCode>
713  </Address>
714  </ShipFrom>
715 
716  <Package>
717  <PackagingType>
718  <Code>{$params['48_container']}</Code>
719  </PackagingType>
720  <PackageWeight>
721  <UnitOfMeasurement>
722  <Code>{$rowRequest->getUnitMeasure()}</Code>
723  </UnitOfMeasurement>
724  <Weight>{$params['23_weight']}</Weight>
725  </PackageWeight>
726  </Package>
727 XMLRequest;
728 
729  if ($this->getConfigFlag('negotiated_active')) {
730  $xmlParams .= "<RateInformation><NegotiatedRatesIndicator/></RateInformation>";
731  }
732  if ($this->getConfigFlag('include_taxes')) {
733  $xmlParams .= "<TaxInformationIndicator/>";
734  }
735 
736  $xmlParams .= <<<XMLRequest
737  </Shipment>
738  </RatingServiceSelectionRequest>
739 XMLRequest;
740 
741  $xmlRequest .= $xmlParams;
742 
743  $xmlResponse = $this->_getCachedQuotes($xmlRequest);
744  if ($xmlResponse === null) {
745  $debugData['request'] = $xmlParams;
746  try {
747  $client = $this->httpClientFactory->create();
748  $client->post($url, $xmlRequest);
749  $xmlResponse = $client->getBody();
750  $debugData['result'] = $xmlResponse;
751  $this->_setCachedQuotes($xmlRequest, $xmlResponse);
752  } catch (\Throwable $e) {
753  $debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];
754  $xmlResponse = '';
755  }
756  $this->_debug($debugData);
757  }
758 
759  return $this->_parseXmlResponse($xmlResponse);
760  }
_parseXmlResponse($xmlResponse)
Definition: Carrier.php:806
getShipmentByCode($code, $origin=null)
Definition: Carrier.php:505
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ _getXmlTracking()

_getXmlTracking (   $trackings)
protected

Get xml tracking

Parameters
string[]$trackings
Returns
Result

RequestOption==>'1' to request all activities

Definition at line 1018 of file Carrier.php.

1019  {
1020  $url = $this->getConfigData('tracking_xml_url');
1021 
1022  foreach ($trackings as $tracking) {
1026  $xmlRequest = <<<XMLAuth
1027 <?xml version="1.0" ?>
1028 <TrackRequest xml:lang="en-US">
1029  <Request>
1030  <RequestAction>Track</RequestAction>
1031  <RequestOption>1</RequestOption>
1032  </Request>
1033  <TrackingNumber>$tracking</TrackingNumber>
1034  <IncludeFreight>01</IncludeFreight>
1035 </TrackRequest>
1036 XMLAuth;
1037  $debugData['request'] = $this->filterDebugData($this->_xmlAccessRequest) . $xmlRequest;
1038  try {
1039  $client = $this->httpClientFactory->create();
1040  $client->post($url, $this->_xmlAccessRequest . $xmlRequest);
1041  $xmlResponse = $client->getBody();
1042  $debugData['result'] = $xmlResponse;
1043  } catch (\Throwable $e) {
1044  $debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];
1045  $xmlResponse = '';
1046  }
1047 
1048  $this->_debug($debugData);
1049  $this->_parseXmlTrackingResponse($tracking, $xmlResponse);
1050  }
1051 
1052  return $this->_result;
1053  }
_parseXmlTrackingResponse($trackingValue, $xmlResponse)
Definition: Carrier.php:1064

◆ _parseCgiResponse()

_parseCgiResponse (   $response)
protected

Prepare shipping rate result based on response

Parameters
string$response
Returns
Result @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 525 of file Carrier.php.

526  {
527  $costArr = [];
528  $priceArr = [];
529  if (strlen(trim($response)) > 0) {
530  $rRows = explode("\n", $response);
531  $allowedMethods = explode(",", $this->getConfigData('allowed_methods'));
532  foreach ($rRows as $rRow) {
533  $row = explode('%', $rRow);
534  switch (substr($row[0], -1)) {
535  case 3:
536  case 4:
537  if (in_array($row[1], $allowedMethods)) {
538  $responsePrice = $this->_localeFormat->getNumber($row[8]);
539  $costArr[$row[1]] = $responsePrice;
540  $priceArr[$row[1]] = $this->getMethodPrice($responsePrice, $row[1]);
541  }
542  break;
543  case 5:
544  $errorTitle = $row[1];
545  $message = __(
546  'Sorry, something went wrong. Please try again or contact us and we\'ll try to help.'
547  );
548  $this->_logger->debug($message . ': ' . $errorTitle);
549  break;
550  case 6:
551  if (in_array($row[3], $allowedMethods)) {
552  $responsePrice = $this->_localeFormat->getNumber($row[10]);
553  $costArr[$row[3]] = $responsePrice;
554  $priceArr[$row[3]] = $this->getMethodPrice($responsePrice, $row[3]);
555  }
556  break;
557  default:
558  break;
559  }
560  }
561  asort($priceArr);
562  }
563 
564  $result = $this->_rateFactory->create();
565 
566  if (empty($priceArr)) {
567  $error = $this->_rateErrorFactory->create();
568  $error->setCarrier('ups');
569  $error->setCarrierTitle($this->getConfigData('title'));
570  $error->setErrorMessage($this->getConfigData('specificerrmsg'));
571  $result->append($error);
572  } else {
573  foreach ($priceArr as $method => $price) {
574  $rate = $this->_rateMethodFactory->create();
575  $rate->setCarrier('ups');
576  $rate->setCarrierTitle($this->getConfigData('title'));
577  $rate->setMethod($method);
578  $methodArray = $this->configHelper->getCode('method', $method);
579  $rate->setMethodTitle($methodArray);
580  $rate->setCost($costArr[$method]);
581  $rate->setPrice($price);
582  $result->append($rate);
583  }
584  }
585 
586  return $result;
587  }
$response
Definition: 404.php:11
__()
Definition: __.php:13
$price
$message
$method
Definition: info.phtml:13

◆ _parseXmlResponse()

_parseXmlResponse (   $xmlResponse)
protected

Prepare shipping rate result based on response

Parameters
mixed$xmlResponse
Returns
Result @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.ExcessiveMethodLength) @SuppressWarnings(PHPMD.ElseExpression)

Definition at line 806 of file Carrier.php.

807  {
808  $costArr = [];
809  $priceArr = [];
810  if (strlen(trim($xmlResponse)) > 0) {
811  $xml = new \Magento\Framework\Simplexml\Config();
812  $xml->loadString($xmlResponse);
813  $arr = $xml->getXpath("//RatingServiceSelectionResponse/Response/ResponseStatusCode/text()");
814  $success = (int)$arr[0];
815  if ($success === 1) {
816  $arr = $xml->getXpath("//RatingServiceSelectionResponse/RatedShipment");
817  $allowedMethods = explode(",", $this->getConfigData('allowed_methods'));
818 
819  // Negotiated rates
820  $negotiatedArr = $xml->getXpath("//RatingServiceSelectionResponse/RatedShipment/NegotiatedRates");
821  $negotiatedActive = $this->getConfigFlag('negotiated_active')
822  && $this->getConfigData('shipper_number')
823  && !empty($negotiatedArr);
824 
825  $allowedCurrencies = $this->_currencyFactory->create()->getConfigAllowCurrencies();
826  foreach ($arr as $shipElement) {
827  $code = (string)$shipElement->Service->Code;
828  if (in_array($code, $allowedMethods)) {
829  //The location of tax information is in a different place
830  // depending on whether we are using negotiated rates or not
831  if ($negotiatedActive) {
832  $includeTaxesArr = $xml->getXpath(
833  "//RatingServiceSelectionResponse/RatedShipment/NegotiatedRates"
834  . "/NetSummaryCharges/TotalChargesWithTaxes"
835  );
836  $includeTaxesActive = $this->getConfigFlag('include_taxes') && !empty($includeTaxesArr);
837  if ($includeTaxesActive) {
838  $cost = $shipElement->NegotiatedRates
839  ->NetSummaryCharges
840  ->TotalChargesWithTaxes
841  ->MonetaryValue;
842 
843  $responseCurrencyCode = $this->mapCurrencyCode(
844  (string)$shipElement->NegotiatedRates
845  ->NetSummaryCharges
846  ->TotalChargesWithTaxes
847  ->CurrencyCode
848  );
849  } else {
850  $cost = $shipElement->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue;
851  $responseCurrencyCode = $this->mapCurrencyCode(
852  (string)$shipElement->NegotiatedRates->NetSummaryCharges->GrandTotal->CurrencyCode
853  );
854  }
855  } else {
856  $includeTaxesArr = $xml->getXpath(
857  "//RatingServiceSelectionResponse/RatedShipment/TotalChargesWithTaxes"
858  );
859  $includeTaxesActive = $this->getConfigFlag('include_taxes') && !empty($includeTaxesArr);
860  if ($includeTaxesActive) {
861  $cost = $shipElement->TotalChargesWithTaxes->MonetaryValue;
862  $responseCurrencyCode = $this->mapCurrencyCode(
863  (string)$shipElement->TotalChargesWithTaxes->CurrencyCode
864  );
865  } else {
866  $cost = $shipElement->TotalCharges->MonetaryValue;
867  $responseCurrencyCode = $this->mapCurrencyCode(
868  (string)$shipElement->TotalCharges->CurrencyCode
869  );
870  }
871  }
872 
873  //convert price with Origin country currency code to base currency code
874  $successConversion = true;
875  if ($responseCurrencyCode) {
876  if (in_array($responseCurrencyCode, $allowedCurrencies)) {
877  $cost = (double)$cost * $this->_getBaseCurrencyRate($responseCurrencyCode);
878  } else {
879  $errorTitle = __(
880  'We can\'t convert a rate from "%1-%2".',
881  $responseCurrencyCode,
882  $this->_request->getPackageCurrency()->getCode()
883  );
884  $error = $this->_rateErrorFactory->create();
885  $error->setCarrier('ups');
886  $error->setCarrierTitle($this->getConfigData('title'));
887  $error->setErrorMessage($errorTitle);
888  $successConversion = false;
889  }
890  }
891 
892  if ($successConversion) {
893  $costArr[$code] = $cost;
894  $priceArr[$code] = $this->getMethodPrice((float)$cost, $code);
895  }
896  }
897  }
898  } else {
899  $arr = $xml->getXpath("//RatingServiceSelectionResponse/Response/Error/ErrorDescription/text()");
900  $errorTitle = (string)$arr[0][0];
901  $error = $this->_rateErrorFactory->create();
902  $error->setCarrier('ups');
903  $error->setCarrierTitle($this->getConfigData('title'));
904  $error->setErrorMessage($this->getConfigData('specificerrmsg'));
905  }
906  }
907 
908  $result = $this->_rateFactory->create();
909 
910  if (empty($priceArr)) {
911  $error = $this->_rateErrorFactory->create();
912  $error->setCarrier('ups');
913  $error->setCarrierTitle($this->getConfigData('title'));
914  if ($this->getConfigData('specificerrmsg') !== '') {
915  $errorTitle = $this->getConfigData('specificerrmsg');
916  }
917  if (!isset($errorTitle)) {
918  $errorTitle = __('Cannot retrieve shipping rates');
919  }
920  $error->setErrorMessage($errorTitle);
921  $result->append($error);
922  } else {
923  foreach ($priceArr as $method => $price) {
924  $rate = $this->_rateMethodFactory->create();
925  $rate->setCarrier('ups');
926  $rate->setCarrierTitle($this->getConfigData('title'));
927  $rate->setMethod($method);
928  $methodArr = $this->getShipmentByCode($method);
929  $rate->setMethodTitle($methodArr);
930  $rate->setCost($costArr[$method]);
931  $rate->setPrice($price);
932  $result->append($rate);
933  }
934  }
935 
936  return $result;
937  }
if(!defined( 'PHP_VERSION_ID')||!(PHP_VERSION_ID===70002||PHP_VERSION_ID===70004||PHP_VERSION_ID >=70006))
Definition: bootstrap.php:14
__()
Definition: __.php:13
$price
$method
Definition: info.phtml:13
getShipmentByCode($code, $origin=null)
Definition: Carrier.php:505
$code
Definition: info.phtml:12

◆ _parseXmlTrackingResponse()

_parseXmlTrackingResponse (   $trackingValue,
  $xmlResponse 
)
protected

Parse xml tracking response

Parameters
string$trackingValue
string$xmlResponse
Returns
null @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 1064 of file Carrier.php.

1065  {
1066  $errorTitle = 'For some reason we can\'t retrieve tracking info right now.';
1067  $resultArr = [];
1068  $packageProgress = [];
1069 
1070  if ($xmlResponse) {
1071  $xml = new \Magento\Framework\Simplexml\Config();
1072  $xml->loadString($xmlResponse);
1073  $arr = $xml->getXpath("//TrackResponse/Response/ResponseStatusCode/text()");
1074  $success = (int)$arr[0][0];
1075 
1076  if ($success === 1) {
1077  $arr = $xml->getXpath("//TrackResponse/Shipment/Service/Description/text()");
1078  $resultArr['service'] = (string)$arr[0];
1079 
1080  $arr = $xml->getXpath("//TrackResponse/Shipment/PickupDate/text()");
1081  $resultArr['shippeddate'] = (string)$arr[0];
1082 
1083  $arr = $xml->getXpath("//TrackResponse/Shipment/Package/PackageWeight/Weight/text()");
1084  $weight = (string)$arr[0];
1085 
1086  $arr = $xml->getXpath("//TrackResponse/Shipment/Package/PackageWeight/UnitOfMeasurement/Code/text()");
1087  $unit = (string)$arr[0];
1088 
1089  $resultArr['weight'] = "{$weight} {$unit}";
1090 
1091  $activityTags = $xml->getXpath("//TrackResponse/Shipment/Package/Activity");
1092  if ($activityTags) {
1093  $index = 1;
1094  foreach ($activityTags as $activityTag) {
1095  $addressArr = [];
1096  if (isset($activityTag->ActivityLocation->Address->City)) {
1097  $addressArr[] = (string)$activityTag->ActivityLocation->Address->City;
1098  }
1099  if (isset($activityTag->ActivityLocation->Address->StateProvinceCode)) {
1100  $addressArr[] = (string)$activityTag->ActivityLocation->Address->StateProvinceCode;
1101  }
1102  if (isset($activityTag->ActivityLocation->Address->CountryCode)) {
1103  $addressArr[] = (string)$activityTag->ActivityLocation->Address->CountryCode;
1104  }
1105  $dateArr = [];
1106  $date = (string)$activityTag->Date;
1107  //YYYYMMDD
1108  $dateArr[] = substr($date, 0, 4);
1109  $dateArr[] = substr($date, 4, 2);
1110  $dateArr[] = substr($date, -2, 2);
1111 
1112  $timeArr = [];
1113  $time = (string)$activityTag->Time;
1114  //HHMMSS
1115  $timeArr[] = substr($time, 0, 2);
1116  $timeArr[] = substr($time, 2, 2);
1117  $timeArr[] = substr($time, -2, 2);
1118 
1119  if ($index === 1) {
1120  $resultArr['status'] = (string)$activityTag->Status->StatusType->Description;
1121  $resultArr['deliverydate'] = implode('-', $dateArr);
1122  //YYYY-MM-DD
1123  $resultArr['deliverytime'] = implode(':', $timeArr);
1124  //HH:MM:SS
1125  $resultArr['deliverylocation'] = (string)$activityTag->ActivityLocation->Description;
1126  $resultArr['signedby'] = (string)$activityTag->ActivityLocation->SignedForByName;
1127  if ($addressArr) {
1128  $resultArr['deliveryto'] = implode(', ', $addressArr);
1129  }
1130  } else {
1131  $tempArr = [];
1132  $tempArr['activity'] = (string)$activityTag->Status->StatusType->Description;
1133  $tempArr['deliverydate'] = implode('-', $dateArr);
1134  //YYYY-MM-DD
1135  $tempArr['deliverytime'] = implode(':', $timeArr);
1136  //HH:MM:SS
1137  if ($addressArr) {
1138  $tempArr['deliverylocation'] = implode(', ', $addressArr);
1139  }
1140  $packageProgress[] = $tempArr;
1141  }
1142  $index++;
1143  }
1144  $resultArr['progressdetail'] = $packageProgress;
1145  }
1146  } else {
1147  $arr = $xml->getXpath("//TrackResponse/Response/Error/ErrorDescription/text()");
1148  $errorTitle = (string)$arr[0][0];
1149  }
1150  }
1151 
1152  if (!$this->_result) {
1153  $this->_result = $this->_trackFactory->create();
1154  }
1155 
1156  if ($resultArr) {
1157  $tracking = $this->_trackStatusFactory->create();
1158  $tracking->setCarrier('ups');
1159  $tracking->setCarrierTitle($this->getConfigData('title'));
1160  $tracking->setTracking($trackingValue);
1161  $tracking->addData($resultArr);
1162  $this->_result->append($tracking);
1163  } else {
1164  $error = $this->_trackErrorFactory->create();
1165  $error->setCarrier('ups');
1166  $error->setCarrierTitle($this->getConfigData('title'));
1167  $error->setTracking($trackingValue);
1168  $error->setErrorMessage($errorTitle);
1169  $this->_result->append($error);
1170  }
1171 
1172  return $this->_result;
1173  }
$index
Definition: list.phtml:44

◆ _sendShipmentAcceptRequest()

_sendShipmentAcceptRequest ( Element  $shipmentConfirmResponse)
protected

Send and process shipment accept request

Parameters
Element$shipmentConfirmResponse
Returns
\Magento\Framework\DataObject

Definition at line 1439 of file Carrier.php.

1440  {
1441  $xmlRequest = $this->_xmlElFactory->create(
1442  ['data' => '<?xml version = "1.0" ?><ShipmentAcceptRequest/>']
1443  );
1444  $request = $xmlRequest->addChild('Request');
1445  $request->addChild('RequestAction', 'ShipAccept');
1446  $xmlRequest->addChild('ShipmentDigest', $shipmentConfirmResponse->ShipmentDigest);
1447  $debugData = ['request' => $this->filterDebugData($this->_xmlAccessRequest) . $xmlRequest->asXML()];
1448 
1449  try {
1450  $client = $this->httpClientFactory->create();
1451  $client->post($this->getShipAcceptUrl(), $this->_xmlAccessRequest . $xmlRequest->asXML());
1452  $xmlResponse = $client->getBody();
1453  $debugData['result'] = $xmlResponse;
1454  $this->_setCachedQuotes($xmlRequest, $xmlResponse);
1455  } catch (\Throwable $e) {
1456  $debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];
1457  $xmlResponse = '';
1458  }
1459 
1460  try {
1461  $response = $this->_xmlElFactory->create(['data' => $xmlResponse]);
1462  } catch (\Throwable $e) {
1463  $debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];
1464  }
1465 
1466  $result = new \Magento\Framework\DataObject();
1467  if (isset($response->Error)) {
1468  $result->setErrors((string)$response->Error->ErrorDescription);
1469  } else {
1470  $shippingLabelContent = (string)$response->ShipmentResults->PackageResults->LabelImage->GraphicImage;
1471  $trackingNumber = (string)$response->ShipmentResults->PackageResults->TrackingNumber;
1472 
1473  $result->setShippingLabelContent(base64_decode($shippingLabelContent));
1474  $result->setTrackingNumber($trackingNumber);
1475  }
1476 
1477  $this->_debug($debugData);
1478 
1479  return $result;
1480  }
$response
Definition: 404.php:11

◆ _setFreeMethodRequest()

_setFreeMethodRequest (   $freeMethod)
protected

Set free method request

Parameters
string$freeMethod
Returns
void

Definition at line 429 of file Carrier.php.

430  {
431  $r = $this->_rawRequest;
432 
433  $weight = $this->getTotalNumOfBoxes($r->getFreeMethodWeight());
434  $weight = $this->_getCorrectWeight($weight);
435  $r->setWeight($weight);
436  $r->setAction($this->configHelper->getCode('action', 'single'));
437  $r->setProduct($freeMethod);
438  }

◆ collectRates()

collectRates ( RateRequest  $request)

Collect and get rates/errors

Parameters
RateRequest$request
Returns
Result|Error|bool

Implements AbstractCarrierInterface.

Definition at line 209 of file Carrier.php.

210  {
211  $this->setRequest($request);
212  if (!$this->canCollectRates()) {
213  return $this->getErrorMessage();
214  }
215 
216  $this->setRequest($request);
217  $this->_result = $this->_getQuotes();
219 
220  return $this->getResult();
221  }
setRequest(RateRequest $request)
Definition: Carrier.php:232

◆ getAllowedMethods()

getAllowedMethods ( )

Get allowed shipping methods

Returns
array

Implements CarrierInterface.

Definition at line 1210 of file Carrier.php.

1211  {
1212  $allowed = explode(',', $this->getConfigData('allowed_methods'));
1213  $arr = [];
1214  $isByCode = $this->getConfigData('type') == 'UPS_XML';
1215  foreach ($allowed as $code) {
1216  $arr[$code] = $isByCode ? $this->getShipmentByCode($code) : $this->configHelper->getCode('method', $code);
1217  }
1218 
1219  return $arr;
1220  }
getShipmentByCode($code, $origin=null)
Definition: Carrier.php:505
$code
Definition: info.phtml:12

◆ getContainerTypes()

getContainerTypes ( \Magento\Framework\DataObject  $params = null)

Return container types of carrier

Parameters
\Magento\Framework\DataObject | null$params
Returns
array|bool @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 1579 of file Carrier.php.

1580  {
1581  if ($params === null) {
1582  return $this->_getAllowedContainers($params);
1583  }
1584  $method = $params->getMethod();
1585  $countryShipper = $params->getCountryShipper();
1586  $countryRecipient = $params->getCountryRecipient();
1587 
1588  if ($countryShipper == self::USA_COUNTRY_ID && $countryRecipient == self::CANADA_COUNTRY_ID ||
1589  $countryShipper == self::CANADA_COUNTRY_ID && $countryRecipient == self::USA_COUNTRY_ID ||
1590  $countryShipper == self::MEXICO_COUNTRY_ID && $countryRecipient == self::USA_COUNTRY_ID && $method == '11'
1591  ) {
1592  $containerTypes = [];
1593  if ($method == '07' || $method == '08' || $method == '65') {
1594  // Worldwide Expedited
1595  if ($method != '08') {
1596  $containerTypes = [
1597  '01' => __('UPS Letter Envelope'),
1598  '24' => __('UPS Worldwide 25 kilo'),
1599  '25' => __('UPS Worldwide 10 kilo'),
1600  ];
1601  }
1602  $containerTypes = $containerTypes + [
1603  '03' => __('UPS Tube'),
1604  '04' => __('PAK'),
1605  '2a' => __('Small Express Box'),
1606  '2b' => __('Medium Express Box'),
1607  '2c' => __('Large Express Box'),
1608  ];
1609  }
1610 
1611  return ['00' => __('Customer Packaging')] + $containerTypes;
1612  } elseif ($countryShipper == self::USA_COUNTRY_ID &&
1613  $countryRecipient == self::PUERTORICO_COUNTRY_ID &&
1614  ($method == '03' ||
1615  $method == '02' ||
1616  $method == '01')
1617  ) {
1618  // Container types should be the same as for domestic
1619  $params->setCountryRecipient(self::USA_COUNTRY_ID);
1620  $containerTypes = $this->_getAllowedContainers($params);
1621  $params->setCountryRecipient($countryRecipient);
1622 
1623  return $containerTypes;
1624  }
1625 
1626  return $this->_getAllowedContainers($params);
1627  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$method
Definition: info.phtml:13
_getAllowedContainers(\Magento\Framework\DataObject $params=null)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getContainerTypesAll()

getContainerTypesAll ( )

Return all container types of carrier

Returns
array|bool

Definition at line 1634 of file Carrier.php.

1635  {
1636  $codes = $this->configHelper->getCode('container');
1637  $descriptions = $this->configHelper->getCode('container_description');
1638  $result = [];
1639  foreach ($codes as $key => &$code) {
1640  $result[$code] = $descriptions[$key];
1641  }
1642 
1643  return $result;
1644  }
$code
Definition: info.phtml:12

◆ getContainerTypesFilter()

getContainerTypesFilter ( )

Return structured data of containers witch related with shipping methods

Returns
array|bool

Definition at line 1651 of file Carrier.php.

1652  {
1653  return $this->configHelper->getCode('containers_filter');
1654  }

◆ getCustomizableContainerTypes()

getCustomizableContainerTypes ( )

Get Container Types, that could be customized for UPS carrier

Returns
array

Implements AbstractCarrierInterface.

Definition at line 1690 of file Carrier.php.

1691  {
1692  $result = [];
1693  $containerTypes = $this->configHelper->getCode('container');
1694  foreach (parent::getCustomizableContainerTypes() as $containerType) {
1695  $result[$containerType] = $containerTypes[$containerType];
1696  }
1697 
1698  return $result;
1699  }

◆ getDeliveryConfirmationTypes()

getDeliveryConfirmationTypes ( \Magento\Framework\DataObject  $params = null)

Return delivery confirmation types of carrier

Parameters
\Magento\Framework\DataObject | null$params
Returns
array|bool

Definition at line 1662 of file Carrier.php.

1663  {
1664  $countryRecipient = $params != null ? $params->getCountryRecipient() : null;
1665  $deliveryConfirmationTypes = [];
1666  switch ($this->_getDeliveryConfirmationLevel($countryRecipient)) {
1668  $deliveryConfirmationTypes = [
1669  1 => __('Delivery Confirmation'),
1670  2 => __('Signature Required'),
1671  3 => __('Adult Signature Required'),
1672  ];
1673  break;
1675  $deliveryConfirmationTypes = [1 => __('Signature Required'), 2 => __('Adult Signature Required')];
1676  break;
1677  default:
1678  break;
1679  }
1680  array_unshift($deliveryConfirmationTypes, __('Not Required'));
1681 
1682  return $deliveryConfirmationTypes;
1683  }
__()
Definition: __.php:13
const DELIVERY_CONFIRMATION_PACKAGE
Definition: Carrier.php:38
const DELIVERY_CONFIRMATION_SHIPMENT
Definition: Carrier.php:36
_getDeliveryConfirmationLevel($countyDestination=null)
Definition: Carrier.php:1708
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getResponse()

getResponse ( )

Get tracking response

Returns
string

Definition at line 1180 of file Carrier.php.

1181  {
1182  $statuses = '';
1183  if ($this->_result instanceof \Magento\Shipping\Model\Tracking\Result) {
1184  $trackings = $this->_result->getAllTrackings();
1185  if ($trackings) {
1186  foreach ($trackings as $tracking) {
1187  $data = $tracking->getAllData();
1188  if ($data) {
1189  if (isset($data['status'])) {
1190  $statuses .= __($data['status']);
1191  } else {
1192  $statuses .= __($data['error_message']);
1193  }
1194  }
1195  }
1196  }
1197  }
1198  if (empty($statuses)) {
1199  $statuses = __('Empty response');
1200  }
1201 
1202  return $statuses;
1203  }
__()
Definition: __.php:13

◆ getResult()

getResult ( )

Get result of request

Returns
Result

Definition at line 399 of file Carrier.php.

400  {
401  return $this->_result;
402  }

◆ getShipAcceptUrl()

getShipAcceptUrl ( )

Get ship accept url

Returns
string

Definition at line 1487 of file Carrier.php.

1488  {
1489  if ($this->getConfigData('is_account_live')) {
1490  $url = $this->_liveUrls['ShipAccept'];
1491  } else {
1492  $url = $this->_defaultUrls['ShipAccept'];
1493  }
1494 
1495  return $url;
1496  }

◆ getShipConfirmUrl()

getShipConfirmUrl ( )

Get ship confirm url

Returns
string

Definition at line 1554 of file Carrier.php.

1555  {
1556  $url = $this->getConfigData('url');
1557  if (!$url) {
1558  if ($this->getConfigData('is_account_live')) {
1559  $url = $this->_liveUrls['ShipConfirm'];
1560 
1561  return $url;
1562  } else {
1563  $url = $this->_defaultUrls['ShipConfirm'];
1564 
1565  return $url;
1566  }
1567  }
1568 
1569  return $url;
1570  }

◆ getShipmentByCode()

getShipmentByCode (   $code,
  $origin = null 
)

Get shipment by code

Parameters
string$code
string$origin
Returns
array|bool

Definition at line 505 of file Carrier.php.

506  {
507  if ($origin === null) {
508  $origin = $this->getConfigData('origin_shipment');
509  }
510  $arr = $this->configHelper->getCode('originShipment', $origin);
511  if (isset($arr[$code])) {
512  return $arr[$code];
513  } else {
514  return false;
515  }
516  }
$code
Definition: info.phtml:12

◆ getTracking()

getTracking (   $trackings)

Get tracking

Parameters
string|string[]$trackings
Returns
Result

Definition at line 945 of file Carrier.php.

946  {
947  if (!is_array($trackings)) {
948  $trackings = [$trackings];
949  }
950 
951  if ($this->getConfigData('type') == 'UPS') {
952  $this->_getCgiTracking($trackings);
953  } elseif ($this->getConfigData('type') == 'UPS_XML') {
954  $this->setXMLAccessRequest();
955  $this->_getXmlTracking($trackings);
956  }
957 
958  return $this->_result;
959  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
_getCgiTracking($trackings)
Definition: Carrier.php:988
_getXmlTracking($trackings)
Definition: Carrier.php:1018

◆ setRequest()

setRequest ( RateRequest  $request)

Prepare and set request to this instance

Parameters
RateRequest$request
Returns
$this @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity) @SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 232 of file Carrier.php.

233  {
234  $this->_request = $request;
235 
236  $rowRequest = new \Magento\Framework\DataObject();
237 
238  if ($request->getLimitMethod()) {
239  $rowRequest->setAction($this->configHelper->getCode('action', 'single'));
240  $rowRequest->setProduct($request->getLimitMethod());
241  } else {
242  $rowRequest->setAction($this->configHelper->getCode('action', 'all'));
243  $rowRequest->setProduct('GND' . $this->getConfigData('dest_type'));
244  }
245 
246  if ($request->getUpsPickup()) {
247  $pickup = $request->getUpsPickup();
248  } else {
249  $pickup = $this->getConfigData('pickup');
250  }
251  $rowRequest->setPickup($this->configHelper->getCode('pickup', $pickup));
252 
253  if ($request->getUpsContainer()) {
254  $container = $request->getUpsContainer();
255  } else {
256  $container = $this->getConfigData('container');
257  }
258  $rowRequest->setContainer($this->configHelper->getCode('container', $container));
259 
260  if ($request->getUpsDestType()) {
261  $destType = $request->getUpsDestType();
262  } else {
263  $destType = $this->getConfigData('dest_type');
264  }
265  $rowRequest->setDestType($this->configHelper->getCode('dest_type', $destType));
266 
267  if ($request->getOrigCountry()) {
268  $origCountry = $request->getOrigCountry();
269  } else {
270  $origCountry = $this->_scopeConfig->getValue(
271  \Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_COUNTRY_ID,
272  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
273  $request->getStoreId()
274  );
275  }
276 
277  $rowRequest->setOrigCountry($this->_countryFactory->create()->load($origCountry)->getData('iso2_code'));
278 
279  if ($request->getOrigRegionCode()) {
280  $origRegionCode = $request->getOrigRegionCode();
281  } else {
282  $origRegionCode = $this->_scopeConfig->getValue(
283  \Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_REGION_ID,
284  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
285  $request->getStoreId()
286  );
287  }
288  if (is_numeric($origRegionCode)) {
289  $origRegionCode = $this->_regionFactory->create()->load($origRegionCode)->getCode();
290  }
291  $rowRequest->setOrigRegionCode($origRegionCode);
292 
293  if ($request->getOrigPostcode()) {
294  $rowRequest->setOrigPostal($request->getOrigPostcode());
295  } else {
296  $rowRequest->setOrigPostal(
297  $this->_scopeConfig->getValue(
298  \Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_ZIP,
299  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
300  $request->getStoreId()
301  )
302  );
303  }
304 
305  if ($request->getOrigCity()) {
306  $rowRequest->setOrigCity($request->getOrigCity());
307  } else {
308  $rowRequest->setOrigCity(
309  $this->_scopeConfig->getValue(
310  \Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_CITY,
311  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
312  $request->getStoreId()
313  )
314  );
315  }
316 
317  if ($request->getDestCountryId()) {
318  $destCountry = $request->getDestCountryId();
319  } else {
320  $destCountry = self::USA_COUNTRY_ID;
321  }
322 
323  //for UPS, puero rico state for US will assume as puerto rico country
324  if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' ||
325  $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)
326  ) {
327  $destCountry = self::PUERTORICO_COUNTRY_ID;
328  }
329 
330  // For UPS, Guam state of the USA will be represented by Guam country
331  if ($destCountry == self::USA_COUNTRY_ID && $request->getDestRegionCode() == self::GUAM_REGION_CODE) {
332  $destCountry = self::GUAM_COUNTRY_ID;
333  }
334 
335  $country = $this->_countryFactory->create()->load($destCountry);
336  $rowRequest->setDestCountry($country->getData('iso2_code') ?: $destCountry);
337 
338  $rowRequest->setDestRegionCode($request->getDestRegionCode());
339 
340  if ($request->getDestPostcode()) {
341  $rowRequest->setDestPostal($request->getDestPostcode());
342  }
343 
344  $weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
345 
346  $weight = $this->_getCorrectWeight($weight);
347 
348  $rowRequest->setWeight($weight);
349  if ($request->getFreeMethodWeight() != $request->getPackageWeight()) {
350  $rowRequest->setFreeMethodWeight($request->getFreeMethodWeight());
351  }
352 
353  $rowRequest->setValue($request->getPackageValue());
354  $rowRequest->setValueWithDiscount($request->getPackageValueWithDiscount());
355 
356  if ($request->getUpsUnitMeasure()) {
357  $unit = $request->getUpsUnitMeasure();
358  } else {
359  $unit = $this->getConfigData('unit_of_measure');
360  }
361  $rowRequest->setUnitMeasure($unit);
362  $rowRequest->setIsReturn($request->getIsReturn());
363  $rowRequest->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax());
364 
365  $this->_rawRequest = $rowRequest;
366 
367  return $this;
368  }

◆ setXMLAccessRequest()

setXMLAccessRequest ( )
protected

Set xml access request

Returns
void

Definition at line 966 of file Carrier.php.

967  {
968  $userId = $this->getConfigData('username');
969  $userIdPass = $this->getConfigData('password');
970  $accessKey = $this->getConfigData('access_license_number');
971 
972  $this->_xmlAccessRequest = <<<XMLAuth
973 <?xml version="1.0" ?>
974 <AccessRequest xml:lang="en-US">
975  <AccessLicenseNumber>$accessKey</AccessLicenseNumber>
976  <UserId>$userId</UserId>
977  <Password>$userIdPass</Password>
978 </AccessRequest>
979 XMLAuth;
980  }

Field Documentation

◆ $_baseCurrencyRate

$_baseCurrencyRate
protected

Definition at line 66 of file Carrier.php.

◆ $_code

$_code = self::CODE
protected

Definition at line 45 of file Carrier.php.

◆ $_customizableContainerTypes

$_customizableContainerTypes = ['CP', 'CSP']
protected

Definition at line 107 of file Carrier.php.

◆ $_debugReplacePrivateDataKeys

$_debugReplacePrivateDataKeys
protected
Initial value:
= [
'UserId', 'Password', 'AccessLicenseNumber'
]

Definition at line 127 of file Carrier.php.

◆ $_defaultCgiGatewayUrl

$_defaultCgiGatewayUrl = 'http://www.ups.com:80/using/services/rave/qcostcgi.cgi'
protected

Definition at line 80 of file Carrier.php.

◆ $_defaultUrls

$_defaultUrls
protected
Initial value:
= [
'ShipConfirm' => 'https:
'ShipAccept' => 'https:
]

Definition at line 87 of file Carrier.php.

◆ $_liveUrls

$_liveUrls
protected
Initial value:
= [
'ShipConfirm' => 'https:
'ShipAccept' => 'https:
]

Definition at line 97 of file Carrier.php.

◆ $_localeFormat

$_localeFormat
protected

Definition at line 112 of file Carrier.php.

◆ $_logger

$_logger
protected

Definition at line 117 of file Carrier.php.

◆ $_request

$_request
protected

Definition at line 52 of file Carrier.php.

◆ $_result

$_result
protected

Definition at line 59 of file Carrier.php.

◆ $_xmlAccessRequest

$_xmlAccessRequest
protected

Definition at line 73 of file Carrier.php.

◆ $configHelper

$configHelper
protected

Definition at line 122 of file Carrier.php.

◆ CODE

const CODE = 'ups'

Definition at line 31 of file Carrier.php.

◆ DELIVERY_CONFIRMATION_PACKAGE

const DELIVERY_CONFIRMATION_PACKAGE = 2

Definition at line 38 of file Carrier.php.

◆ DELIVERY_CONFIRMATION_SHIPMENT

const DELIVERY_CONFIRMATION_SHIPMENT = 1

Delivery Confirmation level based on origin/destination

Definition at line 36 of file Carrier.php.


The documentation for this class was generated from the following file: