ResponseErrorProcessor.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Dhl\Model\Validator;
  7. /**
  8. * Performs XML and string processing for errors produced by the DHL shipping service
  9. */
  10. class ResponseErrorProcessor
  11. {
  12. /**
  13. * Processes error encountered in DHL XML response
  14. *
  15. * @param \SimpleXMLElement $xml
  16. * @param bool $isShippingLabel
  17. * @return \Magento\Framework\Phrase
  18. */
  19. public function process($xml, $isShippingLabel)
  20. {
  21. $code = null;
  22. $data = null;
  23. $nodeCondition = isset($xml->Response->Status->Condition)
  24. ? $xml->Response->Status->Condition : $xml->GetQuoteResponse->Note->Condition;
  25. if ($isShippingLabel) {
  26. foreach ($nodeCondition as $condition) {
  27. $code = (string)$condition->ConditionCode;
  28. $data = (string)$condition->ConditionData;
  29. if (!empty($code) && !empty($data)) {
  30. break;
  31. }
  32. }
  33. return __('Error #%1 : %2', trim($code), trim($data));
  34. }
  35. $code = (string)$nodeCondition->ConditionCode ?: 0;
  36. $data = (string)$nodeCondition->ConditionData ?: '';
  37. return __('Error #%1 : %2', trim($code), trim($data));
  38. }
  39. }