Items.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 Temando\Shipping\Model\ResourceModel\Rma\RmaAccess;
  8. use Temando\Shipping\Model\Shipment\PackageInterface;
  9. /**
  10. * View model for RMA shipment items.
  11. *
  12. * @package Temando\Shipping\ViewModel
  13. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  14. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  15. * @link http://www.temando.com/
  16. */
  17. class Items implements ArgumentInterface
  18. {
  19. /**
  20. * @var RmaAccess
  21. */
  22. private $rmaAccess;
  23. /**
  24. * Items constructor.
  25. * @param RmaAccess $rmaAccess
  26. */
  27. public function __construct(RmaAccess $rmaAccess)
  28. {
  29. $this->rmaAccess = $rmaAccess;
  30. }
  31. /**
  32. * @return \Temando\Shipping\Model\Shipment\PackageItem[]
  33. */
  34. public function getRmaShipmentItems()
  35. {
  36. $packages = $this->rmaAccess->getCurrentRmaShipment()->getPackages();
  37. $collectPackageItems = function (array $packageItems, PackageInterface $package) {
  38. return array_merge($packageItems, $package->getItems());
  39. };
  40. $allItems = array_reduce($packages, $collectPackageItems, []);
  41. return $allItems;
  42. }
  43. }