Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetHasDownloadableProductsObserver.php
Go to the documentation of this file.
1 <?php
7 
9 
11 {
15  protected $_checkoutSession;
16 
20  public function __construct(
21  \Magento\Checkout\Model\Session $checkoutSession
22  ) {
23  $this->_checkoutSession = $checkoutSession;
24  }
25 
32  public function execute(\Magento\Framework\Event\Observer $observer)
33  {
34  if (!$this->_checkoutSession->getHasDownloadableProducts()) {
35  $order = $observer->getEvent()->getOrder();
36  foreach ($order->getAllItems() as $item) {
37  /* @var $item \Magento\Sales\Model\Order\Item */
40  || $item->getProductOptionByCode(
41  'is_downloadable'
42  )
43  ) {
44  $this->_checkoutSession->setHasDownloadableProducts(true);
45  break;
46  }
47  }
48  }
49 
50  return $this;
51  }
52 }
$order
Definition: order.php:55