AddOns.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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\Framework\DataObject;
  9. use Temando\Shipping\Model\Shipment\CapabilityInterface;
  10. use Temando\Shipping\Model\Shipment\ShipmentProviderInterface;
  11. use Temando\Shipping\Model\ShipmentInterface;
  12. /**
  13. * Temando AddOn Listing Layout Block
  14. *
  15. * @deprecated since 1.2.0 | Block data is provided by view model
  16. * @see \Temando\Shipping\ViewModel\Shipment\AddOns
  17. *
  18. * @package Temando\Shipping\Block
  19. * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
  20. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  21. * @link http://www.temando.com/
  22. *
  23. * @api
  24. */
  25. class AddOns extends BackendTemplate
  26. {
  27. /**
  28. * @var ShipmentProviderInterface
  29. */
  30. private $shipmentProvider;
  31. /**
  32. * @param Context $context
  33. * @param ShipmentProviderInterface $shipmentProvider
  34. * @param mixed[] $data
  35. */
  36. public function __construct(
  37. Context $context,
  38. ShipmentProviderInterface $shipmentProvider,
  39. array $data = []
  40. ) {
  41. $this->shipmentProvider = $shipmentProvider;
  42. parent::__construct($context, $data);
  43. }
  44. /**
  45. * @return DataObject[]
  46. */
  47. public function getCapabilities()
  48. {
  49. /** @var ShipmentInterface $shipment */
  50. $shipment = $this->shipmentProvider->getShipment();
  51. if ($shipment) {
  52. /** @var DataObject[] $capabilities */
  53. $capabilities = $shipment->getCapabilities();
  54. } else {
  55. $capabilities = [];
  56. }
  57. return $capabilities;
  58. }
  59. /**
  60. * @return string
  61. */
  62. public function getAddressType()
  63. {
  64. /** @var ShipmentInterface $shipment */
  65. $shipment = $this->shipmentProvider->getShipment();
  66. return ($shipment ? $shipment->getDestinationLocation()->getType() : '');
  67. }
  68. /**
  69. * @param DataObject $capability
  70. *
  71. * @return string
  72. */
  73. public function renderCapability(DataObject $capability)
  74. {
  75. /** @var BackendTemplate $addOnBlock */
  76. $addOnBlock = $this->getChildBlock('addon_item');
  77. $addOnBlock->setData('capability', $capability);
  78. $templates = $this->getData('templates');
  79. /** @var CapabilityInterface $capability */
  80. if (!isset($templates[$capability->getCapabilityId()])) {
  81. $addOnBlock->setTemplate($templates['default']);
  82. } else {
  83. $addOnBlock->setTemplate($templates[$capability->getCapabilityId()]);
  84. }
  85. return $addOnBlock->toHtml();
  86. }
  87. /**
  88. * @param string $addressType
  89. * @return string
  90. */
  91. public function renderAddressType($addressType)
  92. {
  93. /** @var BackendTemplate $addOnBlock */
  94. $addOnBlock = $this->getChildBlock('addon_item');
  95. $addOnBlock->setData('addressType', $addressType);
  96. $templates = $this->getData('templates');
  97. $addOnBlock->setTemplate($templates['addressType']);
  98. return $addOnBlock->toHtml();
  99. }
  100. }