6
6
7
7
namespace Magento \CatalogInventory \Observer ;
8
8
9
+ use Magento \CatalogInventory \Model \Configuration ;
9
10
use Magento \Framework \Event \ObserverInterface ;
10
11
use Magento \CatalogInventory \Api \StockManagementInterface ;
11
12
use Magento \Framework \Event \Observer as EventObserver ;
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
*/
@@ -30,9 +36,11 @@ class CancelOrderItemObserver implements ObserverInterface
30
36
* @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer
31
37
*/
32
38
public function __construct (
39
+ Configuration $ configuration ,
33
40
StockManagementInterface $ stockManagement ,
34
41
\Magento \Catalog \Model \Indexer \Product \Price \Processor $ priceIndexer
35
42
) {
43
+ $ this ->configuration = $ configuration ;
36
44
$ this ->stockManagement = $ stockManagement ;
37
45
$ this ->priceIndexer = $ priceIndexer ;
38
46
}
@@ -49,7 +57,8 @@ public function execute(EventObserver $observer)
49
57
$ item = $ observer ->getEvent ()->getItem ();
50
58
$ children = $ item ->getChildrenItems ();
51
59
$ qty = $ item ->getQtyOrdered () - max ($ item ->getQtyShipped (), $ item ->getQtyInvoiced ()) - $ item ->getQtyCanceled ();
52
- if ($ item ->getId () && $ item ->getProductId () && empty ($ children ) && $ qty ) {
60
+ if ($ item ->getId () && $ item ->getProductId () && empty ($ children ) && $ qty && $ this ->configuration
61
+ ->getCanBackInStock ()) {
53
62
$ this ->stockManagement ->backItemQty ($ item ->getProductId (), $ qty , $ item ->getStore ()->getWebsiteId ());
54
63
}
55
64
$ this ->priceIndexer ->reindexRow ($ item ->getProductId ());
0 commit comments