Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SubtractQuoteInventoryObserver.php
Go to the documentation of this file.
1 <?php
8 
12 
17 {
21  protected $stockManagement;
22 
26  protected $productQty;
27 
31  protected $itemsForReindex;
32 
39  public function __construct(
43  ) {
44  $this->stockManagement = $stockManagement;
45  $this->productQty = $productQty;
46  $this->itemsForReindex = $itemsForReindex;
47  }
48 
58  public function execute(EventObserver $observer)
59  {
61  $quote = $observer->getEvent()->getQuote();
62 
63  // Maybe we've already processed this quote in some event during order placement
64  // e.g. call in event 'sales_model_service_quote_submit_before' and later in 'checkout_submit_all_after'
65  if ($quote->getInventoryProcessed()) {
66  return $this;
67  }
68  $items = $this->productQty->getProductQty($quote->getAllItems());
69 
73  $itemsForReindex = $this->stockManagement->registerProductsSale(
74  $items,
75  $quote->getStore()->getWebsiteId()
76  );
77  if (count($itemsForReindex)) {
78  $this->itemsForReindex->setItems($itemsForReindex);
79  }
80  $quote->setInventoryProcessed(true);
81  return $this;
82  }
83 }
$quote
__construct(StockManagementInterface $stockManagement, ProductQty $productQty, ItemsForReindex $itemsForReindex)
$items