diff --git a/InventoryInStorePickup/Model/IsOrderReadyForPickup.php b/InventoryInStorePickup/Model/IsOrderReadyForPickup.php
index 0a5f47e20212..bb9db5b58f89 100644
--- a/InventoryInStorePickup/Model/IsOrderReadyForPickup.php
+++ b/InventoryInStorePickup/Model/IsOrderReadyForPickup.php
@@ -35,6 +35,7 @@ public function __construct(
*/
public function execute(int $orderId):bool
{
+ /*TODO: add $order->canShip() check */
return $this->isFulfilled->execute($orderId);
}
}
diff --git a/InventoryInStorePickup/Model/NotifyOrderIsReadyAndShip.php b/InventoryInStorePickup/Model/NotifyOrderIsReadyAndShip.php
new file mode 100644
index 000000000000..8857f1484f84
--- /dev/null
+++ b/InventoryInStorePickup/Model/NotifyOrderIsReadyAndShip.php
@@ -0,0 +1,53 @@
+isOrderReadyForPickup = $isOrderReadyForPickup;
+ $this->shipOrder = $shipOrder;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function execute(int $orderId):int
+ {
+ if (!$this->isOrderReadyForPickup->execute($orderId)) {
+ throw new OrderIsNotReadyForPickupException();
+ }
+
+ /* TODO: send email */
+
+ return $this->shipOrder->execute($orderId);
+ }
+}
diff --git a/InventoryInStorePickup/etc/di.xml b/InventoryInStorePickup/etc/di.xml
index 04f52ef77cdf..f76750e559df 100644
--- a/InventoryInStorePickup/etc/di.xml
+++ b/InventoryInStorePickup/etc/di.xml
@@ -25,4 +25,10 @@
+
+
+
+
diff --git a/InventoryInStorePickupAdminUi/Block/Adminhtml/Order/View/ReadyForPickup.php b/InventoryInStorePickupAdminUi/Block/Adminhtml/Order/View/ReadyForPickup.php
index ee523b1751bc..54b508a21fbb 100644
--- a/InventoryInStorePickupAdminUi/Block/Adminhtml/Order/View/ReadyForPickup.php
+++ b/InventoryInStorePickupAdminUi/Block/Adminhtml/Order/View/ReadyForPickup.php
@@ -63,8 +63,11 @@ protected function _construct()
$this->_controller = 'adminhtml_order';
$this->_mode = 'view';
+ /* TODO: always display but throw warnings? */
if ($this->isDisplayButton()) {
- $message = __('Are you sure you want to notify the customer that order is ready for pickup?');
+ $message = __(
+ 'Are you sure you want to notify the customer that order is ready for pickup and create shipment?'
+ );
$this->addButton(
'ready_for_pickup',
[
diff --git a/InventoryInStorePickupAdminUi/Controller/Adminhtml/Order/NotifyPickup.php b/InventoryInStorePickupAdminUi/Controller/Adminhtml/Order/NotifyPickup.php
index ae52a9c68cf8..8577ccdf7291 100644
--- a/InventoryInStorePickupAdminUi/Controller/Adminhtml/Order/NotifyPickup.php
+++ b/InventoryInStorePickupAdminUi/Controller/Adminhtml/Order/NotifyPickup.php
@@ -7,7 +7,18 @@
namespace Magento\InventoryInStorePickupAdminUi\Controller\Adminhtml\Order;
-class NotifyPickup extends \Magento\Sales\Controller\Adminhtml\Order
+use Magento\Framework\Exception\InputException;
+use Magento\Framework\Exception\NoSuchEntityException;
+use Magento\InventoryInStorePickupApi\Api\NotifyOrderIsReadyAndShipInterface;
+use Magento\Sales\Api\OrderRepositoryInterface;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Class NotifyPickup
+ *
+ * @package Magento\InventoryInStorePickupAdminUi\Controller\Adminhtml\Order
+ */
+class NotifyPickup extends \Magento\Backend\App\Action
{
/**
* Authorization level of a basic admin session
@@ -16,6 +27,42 @@ class NotifyPickup extends \Magento\Sales\Controller\Adminhtml\Order
*/
const ADMIN_RESOURCE = 'Magento_Sales::emails';
+ /**
+ * @var \Magento\InventoryInStorePickupApi\Api\NotifyOrderIsReadyAndShipInterface
+ */
+ private $notifyOrderIsReadyAndShip;
+
+ /**
+ * @var \Magento\Sales\Api\OrderRepositoryInterface
+ */
+ private $orderRepository;
+
+ /**
+ * @var \Psr\Log\LoggerInterface
+ */
+ private $logger;
+
+ /**
+ * NotifyPickup constructor.
+ *
+ * @param \Magento\Backend\App\Action\Context $context
+ * @param \Magento\InventoryInStorePickupApi\Api\NotifyOrderIsReadyAndShipInterface $notifyOrderIsReadyAndShip
+ * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
+ * @param \Psr\Log\LoggerInterface $logger
+ */
+ public function __construct(
+ \Magento\Backend\App\Action\Context $context,
+ NotifyOrderIsReadyAndShipInterface $notifyOrderIsReadyAndShip,
+ OrderRepositoryInterface $orderRepository,
+ LoggerInterface $logger
+ ) {
+ $this->notifyOrderIsReadyAndShip = $notifyOrderIsReadyAndShip;
+ $this->orderRepository = $orderRepository;
+ $this->logger = $logger;
+
+ parent::__construct($context);
+ }
+
/**
* Notify user
*
@@ -23,16 +70,16 @@ class NotifyPickup extends \Magento\Sales\Controller\Adminhtml\Order
*/
public function execute():\Magento\Framework\Controller\ResultInterface
{
- /*TODO*/
- /*$order = $this->_initOrder();
+ $order = $this->initOrder();
+
if ($order) {
try {
- $this->orderManagement->notify($order->getEntityId());
- $this->messageManager->addSuccessMessage(__('You sent the order email.'));
+ $this->notifyOrderIsReadyAndShip->execute((int)$order->getEntityId());
+ $this->messageManager->addSuccessMessage(__('The customer have been notified and shipment created.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
- $this->messageManager->addErrorMessage(__('We can\'t send the email order right now.'));
+ $this->messageManager->addErrorMessage(__('We can\'t notify the customer right now.'));
$this->logger->critical($e);
}
@@ -42,8 +89,35 @@ public function execute():\Magento\Framework\Controller\ResultInterface
'order_id' => $order->getEntityId()
]
);
- }*/
+ }
return $this->resultRedirectFactory->create()->setPath('sales/*/');
}
+
+ /**
+ * Initialize order model instance
+ *
+ * @see \Magento\Sales\Controller\Adminhtml\Order::_initOrder
+ *
+ * @return \Magento\Sales\Api\Data\OrderInterface|false
+ */
+ private function initOrder()
+ {
+ $id = $this->getRequest()->getParam('order_id');
+ try {
+ $order = $this->orderRepository->get($id);
+ } catch (NoSuchEntityException $e) {
+ $this->messageManager->addErrorMessage(__('This order no longer exists.'));
+ $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
+
+ return false;
+ } catch (InputException $e) {
+ $this->messageManager->addErrorMessage(__('This order no longer exists.'));
+ $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
+
+ return false;
+ }
+
+ return $order;
+ }
}
diff --git a/InventoryInStorePickupApi/Api/NotifyOrderIsReadyAndShipInterface.php b/InventoryInStorePickupApi/Api/NotifyOrderIsReadyAndShipInterface.php
new file mode 100644
index 000000000000..0f06a28fa99e
--- /dev/null
+++ b/InventoryInStorePickupApi/Api/NotifyOrderIsReadyAndShipInterface.php
@@ -0,0 +1,22 @@
+
-