Result.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Shipping\Model\Tracking;
  7. use Magento\Shipping\Model\Rate\Result as RateResult;
  8. use Magento\Shipping\Model\Tracking\Result\AbstractResult;
  9. class Result
  10. {
  11. /**
  12. * @var array
  13. */
  14. protected $_trackings = [];
  15. /**
  16. * @var null|array
  17. */
  18. protected $_error = null;
  19. /**
  20. * Reset tracking
  21. *
  22. * @return $this
  23. */
  24. public function reset()
  25. {
  26. $this->_trackings = [];
  27. return $this;
  28. }
  29. /**
  30. * @param array $error
  31. * @return void
  32. */
  33. public function setError($error)
  34. {
  35. $this->_error = $error;
  36. }
  37. /**
  38. * @return array|null
  39. */
  40. public function getError()
  41. {
  42. return $this->_error;
  43. }
  44. /**
  45. * Add a tracking to the result
  46. *
  47. * @param AbstractResult|RateResult $result
  48. * @return $this
  49. */
  50. public function append($result)
  51. {
  52. if ($result instanceof AbstractResult) {
  53. $this->_trackings[] = $result;
  54. } elseif ($result instanceof RateResult) {
  55. $trackings = $result->getAllTrackings();
  56. foreach ($trackings as $track) {
  57. $this->append($track);
  58. }
  59. }
  60. return $this;
  61. }
  62. /**
  63. * Return all trackings in the result
  64. *
  65. * @return array
  66. */
  67. public function getAllTrackings()
  68. {
  69. return $this->_trackings;
  70. }
  71. }