Overview.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Multishipping\Block\DataProviders;
  8. use Magento\Framework\Session\SessionManagerInterface;
  9. use Magento\Framework\View\Element\Block\ArgumentInterface;
  10. use Magento\Quote\Model\Quote\Address;
  11. /**
  12. * Provides additional data for multishipping checkout overview step.
  13. */
  14. class Overview implements ArgumentInterface
  15. {
  16. /**
  17. * @var SessionManagerInterface
  18. */
  19. private $session;
  20. /**
  21. * @var array
  22. */
  23. private $addressErrors = [];
  24. /**
  25. * @param SessionManagerInterface $session
  26. */
  27. public function __construct(
  28. SessionManagerInterface $session
  29. ) {
  30. $this->session = $session;
  31. }
  32. /**
  33. * Returns address error.
  34. *
  35. * @param Address $address
  36. * @return string
  37. */
  38. public function getAddressError(Address $address): string
  39. {
  40. $addressErrors = $this->getAddressErrors();
  41. return $addressErrors[$address->getId()] ?? '';
  42. }
  43. /**
  44. * Returns all stored errors.
  45. *
  46. * @return array
  47. */
  48. public function getAddressErrors(): array
  49. {
  50. if (empty($this->addressErrors)) {
  51. $this->addressErrors = $this->session->getAddressErrors(true);
  52. }
  53. return $this->addressErrors ?? [];
  54. }
  55. /**
  56. * Creates anchor name for address Id.
  57. *
  58. * @param int $addressId
  59. * @return string
  60. */
  61. public function getAddressAnchorName(int $addressId): string
  62. {
  63. return 'a' . $addressId;
  64. }
  65. }