From ab9e1bac2d0028599875dfaf9dfdb80fbf1e2b2f Mon Sep 17 00:00:00 2001 From: Maksym Novik Date: Thu, 28 Mar 2019 23:27:28 +0200 Subject: [PATCH] Add "Ready for Pickup" button on the Order page in Admin Panel which notifies Customer that Order could be picked up #2034. Moved IsOrderReadyForPickup to API level. Created an init point for NotifyPickup controller. --- .../Model/IsOrderReadyForPickup.php | 40 +++++++++++++++ .../{IsReadyForPickup.php => IsFulfilled.php} | 2 +- .../Adminhtml/Order/View/ReadyForPickup.php | 21 ++++---- .../Adminhtml/Order/NotifyPickup.php | 49 +++++++++++++++++++ .../etc/adminhtml/routes.xml | 14 ++++++ .../Api/IsOrderReadyForPickupInterface.php | 18 +++++++ .../InventoryInStorePickupApi/etc/di.xml | 4 +- 7 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 app/code/Magento/InventoryInStorePickup/Model/IsOrderReadyForPickup.php rename app/code/Magento/InventoryInStorePickup/Model/Order/{IsReadyForPickup.php => IsFulfilled.php} (99%) create mode 100644 app/code/Magento/InventoryInStorePickupAdminUi/Controller/Adminhtml/Order/NotifyPickup.php create mode 100644 app/code/Magento/InventoryInStorePickupAdminUi/etc/adminhtml/routes.xml create mode 100644 app/code/Magento/InventoryInStorePickupApi/Api/IsOrderReadyForPickupInterface.php diff --git a/app/code/Magento/InventoryInStorePickup/Model/IsOrderReadyForPickup.php b/app/code/Magento/InventoryInStorePickup/Model/IsOrderReadyForPickup.php new file mode 100644 index 000000000000..0a5f47e20212 --- /dev/null +++ b/app/code/Magento/InventoryInStorePickup/Model/IsOrderReadyForPickup.php @@ -0,0 +1,40 @@ +isFulfilled = $isFulfilled; + } + + /** + * @param int $orderId + * + * @return bool + */ + public function execute(int $orderId):bool + { + return $this->isFulfilled->execute($orderId); + } +} diff --git a/app/code/Magento/InventoryInStorePickup/Model/Order/IsReadyForPickup.php b/app/code/Magento/InventoryInStorePickup/Model/Order/IsFulfilled.php similarity index 99% rename from app/code/Magento/InventoryInStorePickup/Model/Order/IsReadyForPickup.php rename to app/code/Magento/InventoryInStorePickup/Model/Order/IsFulfilled.php index 522db4a1178c..eaf16114152b 100644 --- a/app/code/Magento/InventoryInStorePickup/Model/Order/IsReadyForPickup.php +++ b/app/code/Magento/InventoryInStorePickup/Model/Order/IsFulfilled.php @@ -9,7 +9,7 @@ use Magento\InventoryApi\Api\Data\SourceItemInterface; -class IsReadyForPickup +class IsFulfilled { /** * @var \Magento\Sales\Api\OrderRepositoryInterface diff --git a/app/code/Magento/InventoryInStorePickupAdminUi/Block/Adminhtml/Order/View/ReadyForPickup.php b/app/code/Magento/InventoryInStorePickupAdminUi/Block/Adminhtml/Order/View/ReadyForPickup.php index f54dd61b769b..ee523b1751bc 100644 --- a/app/code/Magento/InventoryInStorePickupAdminUi/Block/Adminhtml/Order/View/ReadyForPickup.php +++ b/app/code/Magento/InventoryInStorePickupAdminUi/Block/Adminhtml/Order/View/ReadyForPickup.php @@ -7,6 +7,9 @@ namespace Magento\InventoryInStorePickupAdminUi\Block\Adminhtml\Order\View; +use Magento\InventoryInStorePickupAdminUi\Controller\Adminhtml\Order\NotifyPickup; +use Magento\InventoryInStorePickupApi\Api\IsOrderReadyForPickupInterface; + /** * TODO: is it possible to replace with UI Component? * @@ -14,8 +17,6 @@ */ class ReadyForPickup extends \Magento\Backend\Block\Widget\Form\Container { - const ADMIN_SALES_EMAIL_RESOURCE = 'Magento_Sales::emails'; - /** * Block group * @@ -29,22 +30,22 @@ class ReadyForPickup extends \Magento\Backend\Block\Widget\Form\Container private $viewBlock; /** - * @var \Magento\InventoryInStorePickup\Model\Order\IsReadyForPickup + * @var \Magento\InventoryInStorePickupApi\Api\IsOrderReadyForPickupInterface */ private $isReadyForPickup; /** * ReadyForPickup constructor. * - * @param \Magento\Backend\Block\Widget\Context $context - * @param \Magento\Sales\Block\Adminhtml\Order\View $viewBlock - * @param \Magento\InventoryInStorePickup\Model\Order\IsReadyForPickup $isReadyForPickup - * @param array $data + * @param \Magento\Backend\Block\Widget\Context $context + * @param \Magento\Sales\Block\Adminhtml\Order\View $viewBlock + * @param \Magento\InventoryInStorePickupApi\Api\IsOrderReadyForPickupInterface $isReadyForPickup + * @param array $data */ public function __construct( \Magento\Backend\Block\Widget\Context $context, \Magento\Sales\Block\Adminhtml\Order\View $viewBlock, - \Magento\InventoryInStorePickup\Model\Order\IsReadyForPickup $isReadyForPickup, + IsOrderReadyForPickupInterface $isReadyForPickup, array $data = [] ) { $this->viewBlock = $viewBlock; @@ -72,7 +73,7 @@ protected function _construct() 'onclick' => sprintf( "confirmSetLocation('%s', '%s')", $message, - $this->getUrl('*/*/notifyPickup') + $this->viewBlock->getUrl('sales/*/notifyPickup') ) ] ); @@ -84,7 +85,7 @@ protected function _construct() */ private function isEmailsSendingAllowed():bool { - return $this->_authorization->isAllowed(self::ADMIN_SALES_EMAIL_RESOURCE); + return $this->_authorization->isAllowed(NotifyPickup::ADMIN_RESOURCE); } /** diff --git a/app/code/Magento/InventoryInStorePickupAdminUi/Controller/Adminhtml/Order/NotifyPickup.php b/app/code/Magento/InventoryInStorePickupAdminUi/Controller/Adminhtml/Order/NotifyPickup.php new file mode 100644 index 000000000000..ae52a9c68cf8 --- /dev/null +++ b/app/code/Magento/InventoryInStorePickupAdminUi/Controller/Adminhtml/Order/NotifyPickup.php @@ -0,0 +1,49 @@ +_initOrder(); + if ($order) { + try { + $this->orderManagement->notify($order->getEntityId()); + $this->messageManager->addSuccessMessage(__('You sent the order email.')); + } 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->logger->critical($e); + } + + return $this->resultRedirectFactory->create()->setPath( + 'sales/order/view', + [ + 'order_id' => $order->getEntityId() + ] + ); + }*/ + + return $this->resultRedirectFactory->create()->setPath('sales/*/'); + } +} diff --git a/app/code/Magento/InventoryInStorePickupAdminUi/etc/adminhtml/routes.xml b/app/code/Magento/InventoryInStorePickupAdminUi/etc/adminhtml/routes.xml new file mode 100644 index 000000000000..c0d0cd0aaa11 --- /dev/null +++ b/app/code/Magento/InventoryInStorePickupAdminUi/etc/adminhtml/routes.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/app/code/Magento/InventoryInStorePickupApi/Api/IsOrderReadyForPickupInterface.php b/app/code/Magento/InventoryInStorePickupApi/Api/IsOrderReadyForPickupInterface.php new file mode 100644 index 000000000000..d03998bd63ba --- /dev/null +++ b/app/code/Magento/InventoryInStorePickupApi/Api/IsOrderReadyForPickupInterface.php @@ -0,0 +1,18 @@ + + type="Magento\InventoryInStorePickupApi\Model\GetNearbySourcesByPostcode"/> +