/
CatalogProductSaveAfterObserver.php
50 lines (45 loc) · 1.29 KB
/
CatalogProductSaveAfterObserver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Observer\Backend;
use Magento\Framework\Event\ObserverInterface;
class CatalogProductSaveAfterObserver implements ObserverInterface
{
/**
* @var \Magento\Quote\Model\ResourceModel\Quote
*/
protected $_quote;
/**
* @param \Magento\Quote\Model\ResourceModel\Quote $quote
*/
public function __construct(\Magento\Quote\Model\ResourceModel\Quote $quote)
{
$this->_quote = $quote;
}
/**
* Mark recollect contain product(s) quotes
*
* @param int $productId
* @param int $status
* @return void
*/
protected function _recollectQuotes($productId, $status)
{
if ($status != \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) {
$this->_quote->markQuotesRecollect($productId);
}
}
/**
* Catalog Product After Save (change status process)
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$product = $observer->getEvent()->getProduct();
$this->_recollectQuotes($product->getId(), $product->getStatus());
}
}