ChangeQuoteControl.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Quote\Model;
  8. use Magento\Authorization\Model\UserContextInterface;
  9. use Magento\Quote\Api\ChangeQuoteControlInterface;
  10. use Magento\Quote\Api\Data\CartInterface;
  11. /**
  12. * {@inheritdoc}
  13. */
  14. class ChangeQuoteControl implements ChangeQuoteControlInterface
  15. {
  16. /**
  17. * @var UserContextInterface $userContext
  18. */
  19. private $userContext;
  20. /**
  21. * @param UserContextInterface $userContext
  22. */
  23. public function __construct(UserContextInterface $userContext)
  24. {
  25. $this->userContext = $userContext;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function isAllowed(CartInterface $quote): bool
  31. {
  32. switch ($this->userContext->getUserType()) {
  33. case UserContextInterface::USER_TYPE_CUSTOMER:
  34. $isAllowed = ($quote->getCustomerId() == $this->userContext->getUserId());
  35. break;
  36. case UserContextInterface::USER_TYPE_GUEST:
  37. $isAllowed = ($quote->getCustomerId() === null);
  38. break;
  39. case UserContextInterface::USER_TYPE_ADMIN:
  40. case UserContextInterface::USER_TYPE_INTEGRATION:
  41. $isAllowed = true;
  42. break;
  43. default:
  44. $isAllowed = false;
  45. }
  46. return $isAllowed;
  47. }
  48. }