6
6
7
7
namespace Magento \CatalogInventory \Observer ;
8
8
9
- use Magento \Framework \Event \ObserverInterface ;
10
9
use Magento \CatalogInventory \Api \StockManagementInterface ;
10
+ use Magento \CatalogInventory \Model \Configuration ;
11
11
use Magento \Framework \Event \Observer as EventObserver ;
12
+ use Magento \Framework \Event \ObserverInterface ;
12
13
13
14
/**
14
15
* Catalog inventory module observer
15
16
*/
16
17
class CancelOrderItemObserver implements ObserverInterface
17
18
{
19
+ /**
20
+ * @var \Magento\CatalogInventory\Model\Configuration
21
+ */
22
+ protected $ configuration ;
23
+
18
24
/**
19
25
* @var StockManagementInterface
20
26
*/
@@ -26,13 +32,16 @@ class CancelOrderItemObserver implements ObserverInterface
26
32
protected $ priceIndexer ;
27
33
28
34
/**
35
+ * @param Configuration $configuration
29
36
* @param StockManagementInterface $stockManagement
30
37
* @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer
31
38
*/
32
39
public function __construct (
40
+ Configuration $ configuration ,
33
41
StockManagementInterface $ stockManagement ,
34
42
\Magento \Catalog \Model \Indexer \Product \Price \Processor $ priceIndexer
35
43
) {
44
+ $ this ->configuration = $ configuration ;
36
45
$ this ->stockManagement = $ stockManagement ;
37
46
$ this ->priceIndexer = $ priceIndexer ;
38
47
}
@@ -49,7 +58,8 @@ public function execute(EventObserver $observer)
49
58
$ item = $ observer ->getEvent ()->getItem ();
50
59
$ children = $ item ->getChildrenItems ();
51
60
$ qty = $ item ->getQtyOrdered () - max ($ item ->getQtyShipped (), $ item ->getQtyInvoiced ()) - $ item ->getQtyCanceled ();
52
- if ($ item ->getId () && $ item ->getProductId () && empty ($ children ) && $ qty ) {
61
+ if ($ item ->getId () && $ item ->getProductId () && empty ($ children ) && $ qty && $ this ->configuration
62
+ ->getCanBackInStock ()) {
53
63
$ this ->stockManagement ->backItemQty ($ item ->getProductId (), $ qty , $ item ->getStore ()->getWebsiteId ());
54
64
}
55
65
$ this ->priceIndexer ->reindexRow ($ item ->getProductId ());
0 commit comments