Skip to content

Commit f0d9d04

Browse files
committed
MAGETWO-59080: Introduce ability return to stock through api for Configurable and Bundle products
1 parent 84682b7 commit f0d9d04

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

app/code/Magento/SalesInventory/Model/Order/ReturnProcessor.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
*/
1515
class ReturnProcessor
1616
{
17-
/**
18-
* @var \Magento\CatalogInventory\Api\StockConfigurationInterface
19-
*/
20-
private $stockConfiguration;
21-
2217
/**
2318
* @var \Magento\CatalogInventory\Api\StockManagementInterface
2419
*/
@@ -66,7 +61,6 @@ class ReturnProcessor
6661
* @param \Magento\Sales\Api\OrderItemRepositoryInterface $orderItemRepository
6762
*/
6863
public function __construct(
69-
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
7064
\Magento\CatalogInventory\Api\StockManagementInterface $stockManagement,
7165
\Magento\CatalogInventory\Model\Indexer\Stock\Processor $stockIndexer,
7266
\Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer,
@@ -75,7 +69,6 @@ public function __construct(
7569
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
7670
\Magento\Sales\Api\OrderItemRepositoryInterface $orderItemRepository
7771
) {
78-
$this->stockConfiguration = $stockConfiguration;
7972
$this->stockManagement = $stockManagement;
8073
$this->stockIndexerProcessor = $stockIndexer;
8174
$this->priceIndexer = $priceIndexer;
@@ -96,9 +89,6 @@ public function execute(
9689
OrderInterface $order,
9790
array $returnToStockItems = []
9891
) {
99-
if ($this->stockConfiguration->isAutoReturnEnabled()) {
100-
return;
101-
}
10292
$itemsToUpdate = [];
10393
foreach ($creditmemo->getItems() as $item) {
10494
$qty = $item->getQty();

app/code/Magento/SalesInventory/Model/Plugin/Order/ReturnToStockInvoice.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\SalesInventory\Model\Plugin\Order;
77

8+
use Magento\CatalogInventory\Api\StockConfigurationInterface;
89
use Magento\SalesInventory\Model\Order\ReturnProcessor;
910
use Magento\Sales\Api\CreditmemoRepositoryInterface;
1011
use Magento\Sales\Api\InvoiceRepositoryInterface;
@@ -36,23 +37,31 @@ class ReturnToStockInvoice
3637
*/
3738
private $invoiceRepository;
3839

40+
/**
41+
* @var StockConfigurationInterface
42+
*/
43+
private $stockConfiguration;
44+
3945
/**
4046
* ReturnToStockInvoice constructor.
4147
* @param ReturnProcessor $returnProcessor
4248
* @param CreditmemoRepositoryInterface $creditmemoRepository
4349
* @param OrderRepositoryInterface $orderRepository
4450
* @param InvoiceRepositoryInterface $invoiceRepository
51+
* @param StockConfigurationInterface $stockConfiguration
4552
*/
4653
public function __construct(
4754
ReturnProcessor $returnProcessor,
4855
CreditmemoRepositoryInterface $creditmemoRepository,
4956
OrderRepositoryInterface $orderRepository,
50-
InvoiceRepositoryInterface $invoiceRepository
57+
InvoiceRepositoryInterface $invoiceRepository,
58+
StockConfigurationInterface $stockConfiguration
5159
) {
5260
$this->returnProcessor = $returnProcessor;
5361
$this->creditmemoRepository = $creditmemoRepository;
5462
$this->orderRepository = $orderRepository;
5563
$this->invoiceRepository = $invoiceRepository;
64+
$this->stockConfiguration = $stockConfiguration;
5665
}
5766

5867
/**
@@ -79,6 +88,10 @@ public function afterExecute(
7988
\Magento\Sales\Api\Data\CreditmemoCommentCreationInterface $comment = null,
8089
\Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface $arguments = null
8190
) {
91+
if ($this->stockConfiguration->isAutoReturnEnabled()) {
92+
return $resultEntityId;
93+
}
94+
8295
$invoice = $this->invoiceRepository->get($invoiceId);
8396
$order = $this->orderRepository->get($invoice->getOrderId());
8497

app/code/Magento/SalesInventory/Model/Plugin/Order/ReturnToStockOrder.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\SalesInventory\Model\Plugin\Order;
77

8+
use Magento\CatalogInventory\Api\StockConfigurationInterface;
89
use Magento\SalesInventory\Model\Order\ReturnProcessor;
910
use Magento\Sales\Api\CreditmemoRepositoryInterface;
1011
use Magento\Sales\Api\OrderRepositoryInterface;
@@ -30,6 +31,11 @@ class ReturnToStockOrder
3031
*/
3132
private $orderRepository;
3233

34+
/**
35+
* @var StockConfigurationInterface
36+
*/
37+
private $stockConfiguration;
38+
3339
/**
3440
* ReturnToStockPlugin constructor.
3541
*
@@ -40,11 +46,13 @@ class ReturnToStockOrder
4046
public function __construct(
4147
ReturnProcessor $returnProcessor,
4248
CreditmemoRepositoryInterface $creditmemoRepository,
43-
OrderRepositoryInterface $orderRepository
49+
OrderRepositoryInterface $orderRepository,
50+
StockConfigurationInterface $stockConfiguration
4451
) {
4552
$this->returnProcessor = $returnProcessor;
4653
$this->creditmemoRepository = $creditmemoRepository;
4754
$this->orderRepository = $orderRepository;
55+
$this->stockConfiguration = $stockConfiguration;
4856
}
4957

5058
/**
@@ -69,6 +77,10 @@ public function afterExecute(
6977
\Magento\Sales\Api\Data\CreditmemoCommentCreationInterface $comment = null,
7078
\Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface $arguments = null
7179
) {
80+
if ($this->stockConfiguration->isAutoReturnEnabled()) {
81+
return $resultEntityId;
82+
}
83+
7284
$order = $this->orderRepository->get($orderId);
7385

7486
$returnToStockItems = [];

0 commit comments

Comments
 (0)