-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Ready for Pickup" button on the Order page in Admin Panel which …
…notifies Customer that Order could be picked up #2034. Added check if order is ready for pickup
- Loading branch information
Showing
5 changed files
with
139 additions
and
9 deletions.
There are no files selected for viewing
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,93 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Model\Order; | ||
|
||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
|
||
class IsReadyForPickup | ||
{ | ||
/** | ||
* @var \Magento\Sales\Api\OrderRepositoryInterface | ||
*/ | ||
private $orderRepository; | ||
|
||
/** | ||
* @var \Magento\InventoryApi\Api\SourceItemRepositoryInterface | ||
*/ | ||
private $sourceItemRepository; | ||
|
||
/** | ||
* @var \Magento\Framework\Api\SearchCriteriaBuilderFactory | ||
*/ | ||
private $searchCriteriaBuilderFactory; | ||
|
||
/** | ||
* IsReadyForPickup constructor. | ||
* | ||
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository | ||
* @param \Magento\InventoryApi\Api\SourceItemRepositoryInterface $sourceItemRepository | ||
* @param \Magento\Framework\Api\SearchCriteriaBuilderFactory $searchCriteriaBuilder | ||
*/ | ||
public function __construct( | ||
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository, | ||
\Magento\InventoryApi\Api\SourceItemRepositoryInterface $sourceItemRepository, | ||
\Magento\Framework\Api\SearchCriteriaBuilderFactory $searchCriteriaBuilder | ||
) { | ||
$this->orderRepository = $orderRepository; | ||
$this->sourceItemRepository = $sourceItemRepository; | ||
$this->searchCriteriaBuilderFactory = $searchCriteriaBuilder; | ||
} | ||
|
||
/** | ||
* @param int $orderId | ||
* | ||
* @return bool | ||
*/ | ||
public function execute(int $orderId):bool | ||
{ | ||
$order = $this->orderRepository->get($orderId); | ||
|
||
if ($sourceCode = $order->getExtensionAttributes()->getPickupLocationCode()) { | ||
foreach ($order->getItems() as $item) { | ||
if (!$this->isItemFulfilled($item->getSku(), $sourceCode, (float)$item->getQtyOrdered())) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param string $sku | ||
* @param string $sourceCode | ||
* @param float $qtyOrdered | ||
* | ||
* @return bool | ||
*/ | ||
private function isItemFulfilled(string $sku, string $sourceCode, float $qtyOrdered):bool | ||
{ | ||
$searchCriteria = $this->searchCriteriaBuilderFactory | ||
->create() | ||
->addFilter(SourceItemInterface::SOURCE_CODE, $sourceCode) | ||
->addFilter(SourceItemInterface::SKU, $sku) | ||
->create(); | ||
|
||
$sourceItems = $this->sourceItemRepository->getList($searchCriteria); | ||
if ($sourceItems->getTotalCount()) { | ||
/** @var SourceItemInterface $sourceItem */ | ||
$sourceItem = current($sourceItems->getItems()); | ||
|
||
return $sourceItem->getQuantity() >= $qtyOrdered; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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
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
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
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