Location.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\ViewModel\Rma\RmaShipment;
  6. use Magento\Framework\View\Element\Block\ArgumentInterface;
  7. use Magento\Sales\Api\Data\OrderAddressInterfaceFactory;
  8. use Magento\Sales\Model\Order\Address\Renderer as AddressRenderer;
  9. use Temando\Shipping\Model\ResourceModel\Rma\RmaAccess;
  10. /**
  11. * View model for RMA shipment location.
  12. *
  13. * @package Temando\Shipping\ViewModel
  14. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  15. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  16. * @link http://www.temando.com/
  17. *
  18. * @deprecated since 1.1.3
  19. * @see \Temando\Shipping\ViewModel\Order\Location
  20. */
  21. class Location implements ArgumentInterface
  22. {
  23. /**
  24. * @var RmaAccess
  25. */
  26. private $rmaAccess;
  27. /**
  28. * @var OrderAddressInterfaceFactory
  29. */
  30. private $addressFactory;
  31. /**
  32. * @var AddressRenderer
  33. */
  34. private $addressRenderer;
  35. /**
  36. * Location constructor.
  37. * @param RmaAccess $rmaAccess
  38. * @param OrderAddressInterfaceFactory $addressFactory
  39. * @param AddressRenderer $addressRenderer
  40. */
  41. public function __construct(
  42. RmaAccess $rmaAccess,
  43. OrderAddressInterfaceFactory $addressFactory,
  44. AddressRenderer $addressRenderer
  45. ) {
  46. $this->rmaAccess = $rmaAccess;
  47. $this->addressFactory = $addressFactory;
  48. $this->addressRenderer = $addressRenderer;
  49. }
  50. /**
  51. * @param string[] $addressData
  52. * @return string
  53. */
  54. private function getFormattedAddress(array $addressData)
  55. {
  56. /** @var \Magento\Sales\Model\Order\Address $address */
  57. $address = $this->addressFactory->create(['data' => $addressData]);
  58. $formattedAddress = $this->addressRenderer->format($address, 'html');
  59. return (string) $formattedAddress;
  60. }
  61. /**
  62. * @return string
  63. */
  64. public function getReturnFromAddressHtml()
  65. {
  66. $originLocation = $this->rmaAccess->getCurrentRmaShipment()->getOriginLocation();
  67. $addressData = [
  68. 'firstname' => $originLocation->getPersonFirstName(),
  69. 'lastname' => $originLocation->getPersonLastName(),
  70. 'company' => $originLocation->getCompany(),
  71. 'street' => $originLocation->getStreet(),
  72. 'region' => $originLocation->getRegionCode(),
  73. 'city' => $originLocation->getCity(),
  74. 'postcode' => $originLocation->getPostalCode(),
  75. 'country_id' => $originLocation->getCountryCode(),
  76. 'email' => $originLocation->getEmail(),
  77. 'telephone' => $originLocation->getPhoneNumber()
  78. ];
  79. return $this->getFormattedAddress($addressData);
  80. }
  81. /**
  82. * @return string
  83. */
  84. public function getReturnToAddressHtml()
  85. {
  86. $destinationLocation = $this->rmaAccess->getCurrentRmaShipment()->getDestinationLocation();
  87. $addressData = [
  88. 'firstname' => $destinationLocation->getPersonFirstName(),
  89. 'lastname' => $destinationLocation->getPersonLastName(),
  90. 'company' => $destinationLocation->getCompany(),
  91. 'street' => $destinationLocation->getStreet(),
  92. 'region' => $destinationLocation->getRegionCode(),
  93. 'city' => $destinationLocation->getCity(),
  94. 'postcode' => $destinationLocation->getPostalCode(),
  95. 'country_id' => $destinationLocation->getCountryCode(),
  96. 'email' => $destinationLocation->getEmail(),
  97. 'telephone' => $destinationLocation->getPhoneNumber()
  98. ];
  99. return $this->getFormattedAddress($addressData);
  100. }
  101. }