OriginLocation.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Block\Adminhtml\Shipping\View;
  6. use Magento\Backend\Block\Template as BackendTemplate;
  7. use Magento\Backend\Block\Template\Context;
  8. use Magento\Sales\Api\Data\OrderAddressInterfaceFactory;
  9. use Magento\Sales\Model\Order\Address\Renderer as AddressRenderer;
  10. use Temando\Shipping\Model\Shipment\ShipmentProviderInterface;
  11. /**
  12. * Temando Origin Location Layout Block
  13. *
  14. * @package Temando\Shipping\Block
  15. * @author Benjamin Heuer <benjamin.heuer@netresearch.de>
  16. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  17. * @link http://www.temando.com/
  18. *
  19. * @api
  20. * @deprecated since 1.0.5 | Block data is provided by view model
  21. * @see \Temando\Shipping\ViewModel\Order\Location
  22. */
  23. class OriginLocation extends BackendTemplate
  24. {
  25. /**
  26. * @var OrderAddressInterfaceFactory
  27. */
  28. private $addressFactory;
  29. /**
  30. * @var AddressRenderer
  31. */
  32. private $addressRenderer;
  33. /**
  34. * @var ShipmentProviderInterface
  35. */
  36. private $shipmentProvider;
  37. /**
  38. * OriginLocation constructor.
  39. *
  40. * @param Context $context
  41. * @param OrderAddressInterfaceFactory $addressFactory
  42. * @param AddressRenderer $addressRenderer
  43. * @param ShipmentProviderInterface $shipmentProvider
  44. * @param mixed[] $data
  45. */
  46. public function __construct(
  47. Context $context,
  48. OrderAddressInterfaceFactory $addressFactory,
  49. AddressRenderer $addressRenderer,
  50. ShipmentProviderInterface $shipmentProvider,
  51. array $data = []
  52. ) {
  53. $this->addressFactory = $addressFactory;
  54. $this->addressRenderer = $addressRenderer;
  55. $this->shipmentProvider = $shipmentProvider;
  56. parent::__construct($context, $data);
  57. }
  58. /**
  59. * @return string
  60. */
  61. public function getFormattedAddress()
  62. {
  63. /** @var \Temando\Shipping\Model\ShipmentInterface $shipment */
  64. $shipment = $this->shipmentProvider->getShipment();
  65. if (!$shipment) {
  66. return '';
  67. }
  68. $originLocation = $shipment->getOriginLocation();
  69. $addressData = [
  70. 'region' => $originLocation->getRegionCode(),
  71. 'postcode' => $originLocation->getPostalCode(),
  72. 'lastname' => $originLocation->getPersonLastName(),
  73. 'street' => $originLocation->getStreet(),
  74. 'city' => $originLocation->getCity(),
  75. 'email' => $originLocation->getEmail(),
  76. 'telephone' => $originLocation->getPhoneNumber(),
  77. 'country_id' => $originLocation->getCountryCode(),
  78. 'firstname' => $originLocation->getPersonFirstName(),
  79. 'company' => $originLocation->getCompany()
  80. ];
  81. /** @var \Magento\Sales\Api\Data\OrderAddressInterface|\Magento\Sales\Model\Order\Address $address */
  82. $address = $this->addressFactory->create(['data' => $addressData]);
  83. $formattedAddress = $this->addressRenderer->format($address, 'html');
  84. return (string) $formattedAddress;
  85. }
  86. }