forked from AmpersandHQ/magento2-disable-stock-reservation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Plugin to ensure shipment can be sent with qty is 0, solves issue …
- Loading branch information
Waleed
committed
Apr 18, 2023
1 parent
be5fa4c
commit ce503e8
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/Model/InventoryApi/GetInStockSourceItemsBySkusAndSortedSource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Ampersand\DisableStockReservation\Model\InventoryApi; | ||
|
||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
use Magento\InventoryApi\Api\SourceItemRepositoryInterface; | ||
|
||
class GetInStockSourceItemsBySkusAndSortedSource | ||
{ | ||
/** | ||
* @var SourceItemRepositoryInterface | ||
*/ | ||
private $sourceItemRepository; | ||
|
||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
private $searchCriteriaBuilder; | ||
|
||
/** | ||
* @param SourceItemRepositoryInterface $sourceItemRepository | ||
* @param SearchCriteriaBuilder $searchCriteriaBuilder | ||
* @SuppressWarnings(PHPMD.LongVariable) | ||
*/ | ||
public function __construct( | ||
SourceItemRepositoryInterface $sourceItemRepository, | ||
SearchCriteriaBuilder $searchCriteriaBuilder | ||
) { | ||
$this->sourceItemRepository = $sourceItemRepository; | ||
$this->searchCriteriaBuilder = $searchCriteriaBuilder; | ||
} | ||
|
||
/** | ||
* Retrieve source items for a defined set of SKUs and sorted source codes | ||
* | ||
* @param array $skus | ||
* @param array $sortedSourceCodes | ||
* @return SourceItemInterface[] | ||
*/ | ||
public function execute(array $skus, array $sortedSourceCodes): array | ||
{ | ||
$skus = array_map('strval', $skus); | ||
$searchCriteria = $this->searchCriteriaBuilder | ||
->addFilter(SourceItemInterface::SKU, $skus, 'in') | ||
->addFilter(SourceItemInterface::SOURCE_CODE, $sortedSourceCodes, 'in') | ||
//->addFilter(SourceItemInterface::STATUS, SourceItemInterface::STATUS_IN_STOCK) | ||
->create(); | ||
|
||
$items = $this->sourceItemRepository->getList($searchCriteria)->getItems(); | ||
|
||
$itemsSorting = []; | ||
foreach ($items as $item) { | ||
$itemsSorting[] = array_search($item->getSourceCode(), $sortedSourceCodes, true); | ||
} | ||
|
||
array_multisort($itemsSorting, SORT_NUMERIC, SORT_ASC, $items); | ||
return $items; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Plugin/InventoryInStorePickupSales/Model/Order/IsFulfillablePlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Ampersand\DisableStockReservation\Plugin\InventoryInStorePickupSales\Model\Order; | ||
|
||
class IsFulfillablePlugin | ||
{ | ||
public function aroundExecute() | ||
{ | ||
return true; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Plugin/InventoryShippingAdminUi/Ui/DataProvider/SourceSelectionDataProviderPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Ampersand\DisableStockReservation\Plugin\InventoryShippingAdminUi\Ui\DataProvider; | ||
|
||
use Magento\InventoryShippingAdminUi\Ui\DataProvider\SourceSelectionDataProvider; | ||
|
||
class SourceSelectionDataProviderPlugin | ||
{ | ||
public function afterGetData(SourceSelectionDataProvider $subject, $result) | ||
{ | ||
foreach ($result as &$data) { | ||
foreach ($data['items'] as &$item) { | ||
$item['isManageStock'] = 0; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters