CustomerGroupRetriever.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model;
  7. use Magento\Backend\Model\Session\Quote;
  8. use Magento\Customer\Api\GroupManagementInterface;
  9. /**
  10. * Class for getting customer group from quote session for adminhtml area.
  11. */
  12. class CustomerGroupRetriever implements \Magento\Customer\Model\Group\RetrieverInterface
  13. {
  14. /**
  15. * @var Quote
  16. */
  17. private $quoteSession;
  18. /**
  19. * @var GroupManagementInterface
  20. */
  21. private $groupManagement;
  22. /**
  23. * @param Quote $quoteSession
  24. * @param GroupManagementInterface $groupManagement
  25. */
  26. public function __construct(Quote $quoteSession, GroupManagementInterface $groupManagement)
  27. {
  28. $this->quoteSession = $quoteSession;
  29. $this->groupManagement = $groupManagement;
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function getCustomerGroupId()
  35. {
  36. if ($this->quoteSession->getQuoteId() && $this->quoteSession->getQuote()) {
  37. return $this->quoteSession->getQuote()->getCustomerGroupId();
  38. }
  39. return $this->groupManagement->getNotLoggedInGroup()->getId();
  40. }
  41. }