OrderViewAuthorization.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Sales\Controller\AbstractController;
  8. class OrderViewAuthorization implements OrderViewAuthorizationInterface
  9. {
  10. /**
  11. * @var \Magento\Customer\Model\Session
  12. */
  13. protected $customerSession;
  14. /**
  15. * @var \Magento\Sales\Model\Order\Config
  16. */
  17. protected $orderConfig;
  18. /**
  19. * @param \Magento\Customer\Model\Session $customerSession
  20. * @param \Magento\Sales\Model\Order\Config $orderConfig
  21. */
  22. public function __construct(
  23. \Magento\Customer\Model\Session $customerSession,
  24. \Magento\Sales\Model\Order\Config $orderConfig
  25. ) {
  26. $this->customerSession = $customerSession;
  27. $this->orderConfig = $orderConfig;
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function canView(\Magento\Sales\Model\Order $order)
  33. {
  34. $customerId = $this->customerSession->getCustomerId();
  35. $availableStatuses = $this->orderConfig->getVisibleOnFrontStatuses();
  36. if ($order->getId()
  37. && $order->getCustomerId()
  38. && $order->getCustomerId() == $customerId
  39. && in_array($order->getStatus(), $availableStatuses, true)
  40. ) {
  41. return true;
  42. }
  43. return false;
  44. }
  45. }