-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Use constructor property promotion in module Sales Inventory #37230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.4-develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,8 +5,14 @@ | |||||
*/ | ||||||
namespace Magento\SalesInventory\Model\Order; | ||||||
|
||||||
use Magento\Catalog\Model\Indexer\Product\Price\Processor as PriceProcessor; | ||||||
use Magento\CatalogInventory\Api\StockManagementInterface; | ||||||
use Magento\CatalogInventory\Model\Indexer\Stock\Processor as StockProcessor; | ||||||
use Magento\Sales\Api\Data\CreditmemoInterface; | ||||||
use Magento\Sales\Api\Data\CreditmemoItemInterface; | ||||||
use Magento\Sales\Api\Data\OrderInterface; | ||||||
use Magento\Sales\Api\OrderItemRepositoryInterface; | ||||||
use Magento\Store\Model\StoreManagerInterface; | ||||||
|
||||||
/** | ||||||
* Class ReturnProcessor | ||||||
|
@@ -17,50 +23,26 @@ | |||||
class ReturnProcessor | ||||||
{ | ||||||
/** | ||||||
* @var \Magento\CatalogInventory\Api\StockManagementInterface | ||||||
*/ | ||||||
private $stockManagement; | ||||||
|
||||||
/** | ||||||
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor | ||||||
* @var StockProcessor | ||||||
*/ | ||||||
private $stockIndexerProcessor; | ||||||
|
||||||
/** | ||||||
* @var \Magento\Catalog\Model\Indexer\Product\Price\Processor | ||||||
*/ | ||||||
private $priceIndexer; | ||||||
|
||||||
/** | ||||||
* @var \Magento\Store\Model\StoreManagerInterface | ||||||
*/ | ||||||
private $storeManager; | ||||||
|
||||||
/** | ||||||
* @var \Magento\Sales\Api\OrderItemRepositoryInterface | ||||||
*/ | ||||||
private $orderItemRepository; | ||||||
|
||||||
/** | ||||||
* ReturnProcessor constructor. | ||||||
* @param \Magento\CatalogInventory\Api\StockManagementInterface $stockManagement | ||||||
* @param \Magento\CatalogInventory\Model\Indexer\Stock\Processor $stockIndexer | ||||||
* @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer | ||||||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager | ||||||
* @param \Magento\Sales\Api\OrderItemRepositoryInterface $orderItemRepository | ||||||
* @param StockManagementInterface $stockManagement | ||||||
* @param StockProcessor $stockIndexer | ||||||
* @param PriceProcessor $priceIndexer | ||||||
* @param StoreManagerInterface $storeManager | ||||||
* @param OrderItemRepositoryInterface $orderItemRepository | ||||||
*/ | ||||||
public function __construct( | ||||||
\Magento\CatalogInventory\Api\StockManagementInterface $stockManagement, | ||||||
\Magento\CatalogInventory\Model\Indexer\Stock\Processor $stockIndexer, | ||||||
\Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer, | ||||||
\Magento\Store\Model\StoreManagerInterface $storeManager, | ||||||
\Magento\Sales\Api\OrderItemRepositoryInterface $orderItemRepository | ||||||
private readonly StockManagementInterface $stockManagement, | ||||||
StockProcessor $stockIndexer, | ||||||
private readonly PriceProcessor $priceIndexer, | ||||||
private readonly StoreManagerInterface $storeManager, | ||||||
private readonly OrderItemRepositoryInterface $orderItemRepository | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A trailing comma makes future additions easier to review.
Suggested change
|
||||||
) { | ||||||
$this->stockManagement = $stockManagement; | ||||||
$this->stockIndexerProcessor = $stockIndexer; | ||||||
$this->priceIndexer = $priceIndexer; | ||||||
$this->storeManager = $storeManager; | ||||||
$this->orderItemRepository = $orderItemRepository; | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -109,14 +91,14 @@ public function execute( | |||||
} | ||||||
|
||||||
/** | ||||||
* @param \Magento\Sales\Api\Data\CreditmemoItemInterface $item | ||||||
* @param CreditmemoItemInterface $item | ||||||
* @param int $qty | ||||||
* @param int[] $returnToStockItems | ||||||
* @param int $parentItemId | ||||||
* @return bool | ||||||
*/ | ||||||
private function canReturnItem( | ||||||
\Magento\Sales\Api\Data\CreditmemoItemInterface $item, | ||||||
CreditmemoItemInterface $item, | ||||||
$qty, | ||||||
$parentItemId = null, | ||||||
array $returnToStockItems = [] | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,6 +6,7 @@ | |||||
namespace Magento\SalesInventory\Model\Order; | ||||||
|
||||||
use Magento\Framework\Exception\NoSuchEntityException; | ||||||
use Magento\Framework\Phrase; | ||||||
use Magento\Sales\Api\Data\CreditmemoInterface; | ||||||
use Magento\Sales\Api\Data\CreditmemoItemInterface; | ||||||
use Magento\Sales\Api\Data\OrderItemInterface; | ||||||
|
@@ -16,24 +17,19 @@ | |||||
*/ | ||||||
class ReturnValidator | ||||||
{ | ||||||
/** | ||||||
* @var OrderItemRepositoryInterface | ||||||
*/ | ||||||
private $orderItemRepository; | ||||||
|
||||||
/** | ||||||
* ReturnValidator constructor. | ||||||
* @param OrderItemRepositoryInterface $orderItemRepository | ||||||
*/ | ||||||
public function __construct(OrderItemRepositoryInterface $orderItemRepository) | ||||||
{ | ||||||
$this->orderItemRepository = $orderItemRepository; | ||||||
public function __construct( | ||||||
private readonly OrderItemRepositoryInterface $orderItemRepository | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A trailing comma makes future additions easier to review.
Suggested change
|
||||||
) { | ||||||
} | ||||||
|
||||||
/** | ||||||
* @param int[] $returnToStockItems | ||||||
* @param CreditmemoInterface $creditmemo | ||||||
* @return \Magento\Framework\Phrase|null | ||||||
* @return Phrase|null | ||||||
*/ | ||||||
public function validate($returnToStockItems, CreditmemoInterface $creditmemo) | ||||||
{ | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ | |||||
*/ | ||||||
namespace Magento\SalesInventory\Model\Plugin\Order\Validation; | ||||||
|
||||||
use Magento\Sales\Api\Data\CreditmemoCommentCreationInterface; | ||||||
use Magento\Sales\Api\Data\InvoiceInterface; | ||||||
use Magento\Sales\Model\Order\Validation\RefundInvoiceInterface; | ||||||
use Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface; | ||||||
|
@@ -18,19 +19,13 @@ | |||||
*/ | ||||||
class InvoiceRefundCreationArguments | ||||||
{ | ||||||
/** | ||||||
* @var ReturnValidator | ||||||
*/ | ||||||
private $returnValidator; | ||||||
|
||||||
/** | ||||||
* InvoiceRefundCreationArguments constructor. | ||||||
* @param ReturnValidator $returnValidator | ||||||
*/ | ||||||
public function __construct( | ||||||
ReturnValidator $returnValidator | ||||||
private readonly ReturnValidator $returnValidator | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A trailing comma makes future additions easier to review.
Suggested change
|
||||||
) { | ||||||
$this->returnValidator = $returnValidator; | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -43,8 +38,8 @@ public function __construct( | |||||
* @param bool $isOnline | ||||||
* @param bool $notify | ||||||
* @param bool $appendComment | ||||||
* @param \Magento\Sales\Api\Data\CreditmemoCommentCreationInterface|null $comment | ||||||
* @param \Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface|null $arguments | ||||||
* @param CreditmemoCommentCreationInterface|null $comment | ||||||
* @param CreditmemoCreationArgumentsInterface|null $arguments | ||||||
* @return ValidatorResultInterface | ||||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||||||
* @SuppressWarnings(PHPMD.ExcessiveParameterList) | ||||||
|
@@ -59,8 +54,8 @@ public function afterValidate( | |||||
$isOnline = false, | ||||||
$notify = false, | ||||||
$appendComment = false, | ||||||
\Magento\Sales\Api\Data\CreditmemoCommentCreationInterface $comment = null, | ||||||
\Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface $arguments = null | ||||||
CreditmemoCommentCreationInterface $comment = null, | ||||||
CreditmemoCreationArgumentsInterface $arguments = null | ||||||
) { | ||||||
if ($this->isReturnToStockItems($arguments)) { | ||||||
return $validationResults; | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,19 +18,13 @@ | |||||
*/ | ||||||
class OrderRefundCreationArguments | ||||||
{ | ||||||
/** | ||||||
* @var ReturnValidator | ||||||
*/ | ||||||
private $returnValidator; | ||||||
|
||||||
/** | ||||||
* OrderRefundCreationArguments constructor. | ||||||
* @param ReturnValidator $returnValidator | ||||||
*/ | ||||||
public function __construct( | ||||||
ReturnValidator $returnValidator | ||||||
private readonly ReturnValidator $returnValidator | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A trailing comma makes future additions easier to review.
Suggested change
|
||||||
) { | ||||||
$this->returnValidator = $returnValidator; | ||||||
} | ||||||
|
||||||
/** | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,10 +6,14 @@ | |||||
|
||||||
namespace Magento\SalesInventory\Observer; | ||||||
|
||||||
use Magento\Catalog\Model\Indexer\Product\Price\Processor as PriceProcessor; | ||||||
use Magento\CatalogInventory\Api\StockConfigurationInterface; | ||||||
use Magento\CatalogInventory\Api\StockManagementInterface; | ||||||
use Magento\CatalogInventory\Model\Indexer\Stock\Processor as StockProcessor; | ||||||
use Magento\Framework\Event\Observer as EventObserver; | ||||||
use Magento\Framework\Event\ObserverInterface; | ||||||
use Magento\Sales\Api\OrderRepositoryInterface; | ||||||
use Magento\Sales\Model\Order\Creditmemo as OrderCreditmemo; | ||||||
use Magento\SalesInventory\Model\Order\ReturnProcessor; | ||||||
|
||||||
/** | ||||||
|
@@ -18,59 +22,23 @@ | |||||
*/ | ||||||
class RefundOrderInventoryObserver implements ObserverInterface | ||||||
{ | ||||||
/** | ||||||
* @var StockConfigurationInterface | ||||||
*/ | ||||||
private $stockConfiguration; | ||||||
|
||||||
/** | ||||||
* @var StockManagementInterface | ||||||
*/ | ||||||
private $stockManagement; | ||||||
|
||||||
/** | ||||||
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor | ||||||
*/ | ||||||
private $stockIndexerProcessor; | ||||||
|
||||||
/** | ||||||
* @var \Magento\Catalog\Model\Indexer\Product\Price\Processor | ||||||
*/ | ||||||
private $priceIndexer; | ||||||
|
||||||
/** | ||||||
* @var \Magento\SalesInventory\Model\Order\ReturnProcessor | ||||||
*/ | ||||||
private $returnProcessor; | ||||||
|
||||||
/** | ||||||
* @var \Magento\Sales\Api\OrderRepositoryInterface | ||||||
*/ | ||||||
private $orderRepository; | ||||||
|
||||||
/** | ||||||
* RefundOrderInventoryObserver constructor. | ||||||
* @param StockConfigurationInterface $stockConfiguration | ||||||
* @param StockManagementInterface $stockManagement | ||||||
* @param \Magento\CatalogInventory\Model\Indexer\Stock\Processor $stockIndexerProcessor | ||||||
* @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer | ||||||
* @param StockProcessor $stockIndexerProcessor | ||||||
* @param PriceProcessor $priceIndexer | ||||||
* @param ReturnProcessor $returnProcessor | ||||||
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository | ||||||
* @param OrderRepositoryInterface $orderRepository | ||||||
*/ | ||||||
public function __construct( | ||||||
StockConfigurationInterface $stockConfiguration, | ||||||
StockManagementInterface $stockManagement, | ||||||
\Magento\CatalogInventory\Model\Indexer\Stock\Processor $stockIndexerProcessor, | ||||||
\Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer, | ||||||
\Magento\SalesInventory\Model\Order\ReturnProcessor $returnProcessor, | ||||||
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository | ||||||
private readonly StockConfigurationInterface $stockConfiguration, | ||||||
private readonly StockManagementInterface $stockManagement, | ||||||
private readonly StockProcessor $stockIndexerProcessor, | ||||||
private readonly PriceProcessor $priceIndexer, | ||||||
private readonly ReturnProcessor $returnProcessor, | ||||||
private readonly OrderRepositoryInterface $orderRepository | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A trailing comma makes future additions easier to review.
Suggested change
|
||||||
) { | ||||||
$this->stockConfiguration = $stockConfiguration; | ||||||
$this->stockManagement = $stockManagement; | ||||||
$this->stockIndexerProcessor = $stockIndexerProcessor; | ||||||
$this->priceIndexer = $priceIndexer; | ||||||
$this->returnProcessor = $returnProcessor; | ||||||
$this->orderRepository = $orderRepository; | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -81,7 +49,7 @@ public function __construct( | |||||
*/ | ||||||
public function execute(EventObserver $observer) | ||||||
{ | ||||||
/* @var $creditmemo \Magento\Sales\Model\Order\Creditmemo */ | ||||||
/* @var OrderCreditmemo $creditmemo */ | ||||||
$creditmemo = $observer->getEvent()->getCreditmemo(); | ||||||
$order = $this->orderRepository->get($creditmemo->getOrderId()); | ||||||
$returnToStockItems = []; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why has this not been promoted?