Authorization.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Model\GuestCartManagement\Plugin;
  7. use Magento\Framework\Exception\StateException;
  8. class Authorization
  9. {
  10. /**
  11. * @var \Magento\Authorization\Model\UserContextInterface
  12. */
  13. protected $userContext;
  14. /**
  15. * @param \Magento\Authorization\Model\UserContextInterface $userContext
  16. */
  17. public function __construct(
  18. \Magento\Authorization\Model\UserContextInterface $userContext
  19. ) {
  20. $this->userContext = $userContext;
  21. }
  22. /**
  23. * @param \Magento\Quote\Model\GuestCart\GuestCartManagement $subject
  24. * @param string $cartId
  25. * @param int $customerId
  26. * @param int $storeId
  27. * @throws StateException
  28. * @return void
  29. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  30. */
  31. public function beforeAssignCustomer(
  32. \Magento\Quote\Model\GuestCart\GuestCartManagement $subject,
  33. $cartId,
  34. $customerId,
  35. $storeId
  36. ) {
  37. if ($customerId !== (int)$this->userContext->getUserId()) {
  38. throw new StateException(
  39. __("You don't have the correct permissions to assign the customer to the cart.")
  40. );
  41. }
  42. }
  43. }