Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CheckoutCartAddProductObserver.php
Go to the documentation of this file.
1 <?php
7 
10 
15 {
19  protected $eventSaver;
20 
24  private $reportStatus;
25 
29  public function __construct(
31  \Magento\Reports\Model\ReportStatus $reportStatus
32  ) {
33  $this->eventSaver = $eventSaver;
34  $this->reportStatus = $reportStatus;
35  }
36 
43  public function execute(\Magento\Framework\Event\Observer $observer)
44  {
45  if (!$this->reportStatus->isReportEnabled(Event::EVENT_PRODUCT_TO_CART)) {
46  return;
47  }
48 
49  $quoteItem = $observer->getEvent()->getItem();
50  if (!$quoteItem->getId() && !$quoteItem->getParentItem()) {
51  $productId = $quoteItem->getProductId();
52  $this->eventSaver->save(Event::EVENT_PRODUCT_TO_CART, $productId);
53  }
54  }
55 }
__construct(EventSaver $eventSaver, \Magento\Reports\Model\ReportStatus $reportStatus)
$quoteItem
Definition: quote.php:38