Skip to content

Commit

Permalink
Add "Ready for Pickup" button on the Order page in Admin Panel which …
Browse files Browse the repository at this point in the history
…notifies Customer that Order could be picked up #2034.

Moved IsOrderReadyForPickup to API level.
Created an init point for NotifyPickup controller.
  • Loading branch information
novikor committed Mar 31, 2019
1 parent 2ccfeb7 commit 3277d05
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 12 deletions.
40 changes: 40 additions & 0 deletions InventoryInStorePickup/Model/IsOrderReadyForPickup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryInStorePickup\Model;

use Magento\InventoryInStorePickup\Model\Order\IsFulfilled;
use Magento\InventoryInStorePickupApi\Api\IsOrderReadyForPickupInterface;

class IsOrderReadyForPickup implements IsOrderReadyForPickupInterface
{
/**
* @var \Magento\InventoryInStorePickup\Model\Order\IsFulfilled
*/
private $isFulfilled;

/**
* IsReadyForPickup constructor.
*
* @param \Magento\InventoryInStorePickup\Model\Order\IsFulfilled $isFulfilled
*/
public function __construct(
IsFulfilled $isFulfilled
) {
$this->isFulfilled = $isFulfilled;
}

/**
* @param int $orderId
*
* @return bool
*/
public function execute(int $orderId):bool
{
return $this->isFulfilled->execute($orderId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use Magento\InventoryApi\Api\Data\SourceItemInterface;

class IsReadyForPickup
class IsFulfilled
{
/**
* @var \Magento\Sales\Api\OrderRepositoryInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

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?
*
* @package Magento\InventoryInStorePickupAdminUi\Block\Adminhtml\Order\View
*/
class ReadyForPickup extends \Magento\Backend\Block\Widget\Form\Container
{
const ADMIN_SALES_EMAIL_RESOURCE = 'Magento_Sales::emails';

/**
* Block group
*
Expand All @@ -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;
Expand Down Expand Up @@ -72,7 +73,7 @@ protected function _construct()
'onclick' => sprintf(
"confirmSetLocation('%s', '%s')",
$message,
$this->getUrl('*/*/notifyPickup')
$this->viewBlock->getUrl('sales/*/notifyPickup')
)
]
);
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryInStorePickupAdminUi\Controller\Adminhtml\Order;

class NotifyPickup extends \Magento\Sales\Controller\Adminhtml\Order
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Sales::emails';

/**
* Notify user
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute():\Magento\Framework\Controller\ResultInterface
{
/*TODO*/
/*$order = $this->_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/*/');
}
}
14 changes: 14 additions & 0 deletions InventoryInStorePickupAdminUi/etc/adminhtml/routes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="sales" frontName="sales">
<module name="Magento_InventoryInStorePickupAdminUi" before="Magento_Backend" />
</route>
</router>
</config>
18 changes: 18 additions & 0 deletions InventoryInStorePickupApi/Api/IsOrderReadyForPickupInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryInStorePickupApi\Api;

interface IsOrderReadyForPickupInterface
{
/**
* @param int $orderId
*
* @return bool
*/
public function execute(int $orderId):bool;
}
4 changes: 3 additions & 1 deletion InventoryInStorePickupApi/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\InventoryInStorePickupApi\Api\GetNearbySourcesByPostcodeInterface"
type="Magento\InventoryInStorePickupApi\Model\GetNearbySourcesByPostcode"/>
type="Magento\InventoryInStorePickupApi\Model\GetNearbySourcesByPostcode"/>
<preference for="\Magento\InventoryInStorePickupApi\Api\IsOrderReadyForPickupInterface"
type="\Magento\InventoryInStorePickup\Model\IsOrderReadyForPickup"/>
</config>

0 comments on commit 3277d05

Please sign in to comment.