Package.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 Temando\Shipping\Model\ResourceModel\Rma\RmaAccess;
  9. use Temando\Shipping\Model\Shipment\PackageInterface;
  10. use Temando\Shipping\Model\Shipment\ShipmentProviderInterface;
  11. use Temando\Shipping\Model\ShipmentInterface;
  12. /**
  13. * Temando Package Listing Layout Block
  14. *
  15. * @package Temando\Shipping\Block
  16. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  17. * @author Rhodri Davies <rhodri.davies@temando.com>
  18. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  19. * @link http://www.temando.com/
  20. *
  21. * @api
  22. * @deprecated since 1.1.3 | Block data is provided by view model
  23. * @see \Temando\Shipping\ViewModel\Shipment\ShipmentDetails
  24. */
  25. class Package extends BackendTemplate
  26. {
  27. /**
  28. * @var ShipmentProviderInterface
  29. */
  30. private $shipmentProvider;
  31. /**
  32. * @var RmaAccess
  33. */
  34. private $rmaAccess;
  35. /**
  36. * @param Context $context
  37. * @param ShipmentProviderInterface $shipmentProvider
  38. * @param RmaAccess $rmaAccess
  39. * @param mixed[] $data
  40. */
  41. public function __construct(
  42. Context $context,
  43. ShipmentProviderInterface $shipmentProvider,
  44. RmaAccess $rmaAccess,
  45. array $data = []
  46. ) {
  47. $this->shipmentProvider = $shipmentProvider;
  48. $this->rmaAccess = $rmaAccess;
  49. parent::__construct($context, $data);
  50. }
  51. /**
  52. * Set package from dispatch or shipment to block
  53. *
  54. * @return BackendTemplate
  55. */
  56. protected function _beforeToHtml()
  57. {
  58. if (!$this->hasData('packages')) {
  59. if ($this->shipmentProvider->getShipment()) {
  60. /** @var ShipmentInterface $platformShipment */
  61. $platformShipment = $this->shipmentProvider->getShipment();
  62. $this->setData('packages', $platformShipment->getPackages());
  63. } elseif ($this->rmaAccess->getCurrentRmaShipment()) {
  64. /** @var ShipmentInterface $platformShipment */
  65. $platformShipment = $this->rmaAccess->getCurrentRmaShipment();
  66. $this->setData('packages', $platformShipment->getPackages());
  67. }
  68. }
  69. return parent::_beforeToHtml();
  70. }
  71. /**
  72. * @return PackageInterface[]
  73. */
  74. public function getPackages()
  75. {
  76. return $this->hasData('packages') ? $this->getData('packages') : [];
  77. }
  78. }