Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IsAllowedGuestCheckoutObserver.php
Go to the documentation of this file.
1 <?php
7 
10 
12 {
16  const XML_PATH_DISABLE_GUEST_CHECKOUT = 'catalog/downloadable/disable_guest_checkout';
17 
23  protected $_scopeConfig;
24 
28  public function __construct(
29  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
30  ) {
31  $this->_scopeConfig = $scopeConfig;
32  }
33 
40  public function execute(\Magento\Framework\Event\Observer $observer)
41  {
42  $store = $observer->getEvent()->getStore();
43  $result = $observer->getEvent()->getResult();
44 
45  if (!$this->_scopeConfig->isSetFlag(
46  self::XML_PATH_DISABLE_GUEST_CHECKOUT,
48  $store
49  )) {
50  return $this;
51  }
52 
53  /* @var $quote \Magento\Quote\Model\Quote */
54  $quote = $observer->getEvent()->getQuote();
55 
56  foreach ($quote->getAllItems() as $item) {
57  if (($product = $item->getProduct())
59  ) {
60  $result->setIsAllowed(false);
61  break;
62  }
63  }
64 
65  return $this;
66  }
67 }
$quote
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)