-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63a1dc5
commit 86484be
Showing
21 changed files
with
642 additions
and
28 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
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Packetery\Checkout\Block\Adminhtml; | ||
|
||
use Magento\Backend\Block\Template; | ||
|
||
class DefaultJs extends Template | ||
{ | ||
/** @var string */ | ||
protected $_template = 'Packetery_Checkout::js.phtml'; | ||
} |
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
49 changes: 49 additions & 0 deletions
49
Packetery/Checkout/Block/Adminhtml/Order/Renderer/Actions.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,49 @@ | ||
<?php | ||
|
||
namespace Packetery\Checkout\Block\Adminhtml\Order\Renderer; | ||
|
||
use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer; | ||
use Magento\Framework\DataObject; | ||
use Packetery\Checkout\Model\Carrier\Config\AllowedMethods; | ||
|
||
class Actions extends AbstractRenderer | ||
{ | ||
/** @var \Magento\Sales\Model\OrderFactory */ | ||
protected $orderFactory; | ||
|
||
/** | ||
* Actions constructor. | ||
* | ||
* @param \Magento\Backend\Block\Context $context | ||
* @param \Magento\Sales\Model\OrderFactory $orderFactory | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
\Magento\Backend\Block\Context $context, | ||
\Magento\Sales\Model\OrderFactory $orderFactory, | ||
array $data = [] | ||
) | ||
{ | ||
$this->orderFactory = $orderFactory; | ||
parent::__construct($context, $data); | ||
} | ||
|
||
/** | ||
* @param \Magento\Framework\DataObject $row | ||
* @return string | ||
*/ | ||
public function render(DataObject $row): string | ||
{ | ||
$orderNumber = $row->getData('order_number'); | ||
$order = $this->orderFactory->create()->loadByIncrementId($orderNumber); | ||
$shippingMethod = $order->getShippingMethod(true); | ||
|
||
$html = ''; | ||
|
||
if ($shippingMethod && ($shippingMethod->getData('method') === AllowedMethods::PICKUP_POINT_DELIVERY || $shippingMethod->getData('method') === 'packetery')) { | ||
$html = '<a href="' . $this->getUrl('packetery/order/detail', array('id' => $row->getData('id'))) . '" title="' . __('Edit') . '" >' . __('Edit') . '</a>'; | ||
} | ||
|
||
return $html; | ||
} | ||
} |
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,69 @@ | ||
<?php | ||
|
||
namespace Packetery\Checkout\Controller\Adminhtml\Order; | ||
|
||
use Magento\Framework\Controller\AbstractResult; | ||
use Packetery\Checkout\Model\Carrier\Config\AllowedMethods; | ||
|
||
class Detail extends \Magento\Backend\App\Action | ||
{ | ||
/** @var \Magento\Framework\View\Result\PageFactory */ | ||
protected $resultPageFactory; | ||
|
||
/** @var \Magento\Sales\Model\OrderFactory */ | ||
private $orderFactory; | ||
|
||
/** @var \Packetery\Checkout\Model\ResourceModel\Order\CollectionFactory */ | ||
private $orderCollectionFactory; | ||
|
||
/** | ||
* Detail constructor. | ||
* | ||
* @param \Magento\Backend\App\Action\Context $context | ||
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory | ||
* @param \Magento\Sales\Model\OrderFactory $orderFactory | ||
* @param \Packetery\Checkout\Model\ResourceModel\Order\CollectionFactory $orderCollection | ||
*/ | ||
public function __construct( | ||
\Magento\Backend\App\Action\Context $context, | ||
\Magento\Framework\View\Result\PageFactory $resultPageFactory, | ||
\Magento\Sales\Model\OrderFactory $orderFactory, | ||
\Packetery\Checkout\Model\ResourceModel\Order\CollectionFactory $orderCollection | ||
) { | ||
parent::__construct($context); | ||
$this->resultPageFactory = $resultPageFactory; | ||
$this->orderFactory = $orderFactory; | ||
$this->orderCollectionFactory = $orderCollection; | ||
} | ||
|
||
/** | ||
* @return \Magento\Framework\Controller\AbstractResult | ||
*/ | ||
public function execute(): AbstractResult | ||
{ | ||
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */ | ||
$resultPage = $this->resultPageFactory->create(); | ||
$resultPage->setActiveMenu('Packetery_Checkout::orders'); | ||
$resultPage->getConfig()->getTitle()->prepend(__('Orders')); | ||
$resultPage->getConfig()->getTitle()->prepend(__('Detail')); | ||
|
||
$id = $this->getRequest()->getParam('id'); | ||
$orderCollection = $this->orderCollectionFactory->create(); | ||
$order = $orderCollection->getItemById($id); | ||
|
||
if (empty($order)) { | ||
$this->messageManager->addErrorMessage(__('Page not found')); | ||
return $this->resultRedirectFactory->create()->setPath('*/*/index'); | ||
} | ||
|
||
$magentoOrder = $this->orderFactory->create()->loadByIncrementId($order->getData('order_number')); | ||
$shippingMethod = $magentoOrder->getShippingMethod(true); | ||
|
||
if (!$shippingMethod || ($shippingMethod->getData('method') !== AllowedMethods::PICKUP_POINT_DELIVERY && $shippingMethod->getData('method') !== 'packetery')) { | ||
$this->messageManager->addErrorMessage(__('Page not found')); | ||
return $this->resultRedirectFactory->create()->setPath('*/*/index'); | ||
} | ||
|
||
return $resultPage; | ||
} | ||
} |
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,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Packetery\Checkout\Controller\Adminhtml\Order; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Framework\App\Action\HttpPostActionInterface; | ||
use Magento\Framework\Controller\Result\Redirect; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\Exception\NotFoundException; | ||
|
||
class Save extends Action implements HttpPostActionInterface | ||
{ | ||
const ADMIN_RESOURCE = 'Packetery_Checkout::packetery'; | ||
|
||
/** @var \Packetery\Checkout\Model\ResourceModel\Order\CollectionFactory */ | ||
private $orderCollectionFactory; | ||
|
||
/** | ||
* Save constructor. | ||
* | ||
* @param \Magento\Backend\App\Action\Context $context | ||
* @param \Packetery\Checkout\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
\Packetery\Checkout\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory | ||
) { | ||
$this->orderCollectionFactory = $orderCollectionFactory; | ||
|
||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* @return Redirect | ||
*/ | ||
public function execute(): Redirect | ||
{ | ||
if (!$this->getRequest()->isPost()) { | ||
throw new NotFoundException(__('Page not found')); | ||
} | ||
|
||
$postData = $this->getRequest()->getPostValue()['general']; | ||
$id = $postData['id']; | ||
$carrierPickupPoint = ($postData['carrier_pickup_point'] ?? null); | ||
|
||
$collection = $this->orderCollectionFactory->create(); | ||
$collection->addFilter('id', $id); | ||
$collection->setDataToAll( | ||
[ | ||
'point_id' => $postData['point_id'], | ||
'point_name' => $postData['point_name'], | ||
'is_carrier' => (bool)$postData['is_carrier'], | ||
'carrier_pickup_point' => ($carrierPickupPoint ?: null), | ||
] | ||
); | ||
$collection->save(); | ||
|
||
$this->messageManager->addSuccessMessage( | ||
__('Saved') | ||
); | ||
|
||
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('packetery/order/detail/id/' . $id); | ||
} | ||
} |
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,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Packetery\Checkout\Ui\Order; | ||
|
||
use Magento\Ui\DataProvider\AbstractDataProvider; | ||
|
||
class DataProvider extends AbstractDataProvider | ||
{ | ||
/** @var \Packetery\Checkout\Model\ResourceModel\Order\Collection */ | ||
protected $collection; | ||
|
||
/** @var \Magento\Sales\Model\OrderFactory */ | ||
private $orderFactory; | ||
|
||
/** | ||
* DataProvider constructor. | ||
* | ||
* @param string $name | ||
* @param string $primaryFieldName | ||
* @param string $requestFieldName | ||
* @param \Packetery\Checkout\Model\ResourceModel\Order\CollectionFactory $collectionFactory | ||
* @param \Magento\Sales\Model\OrderFactory $orderFactory | ||
* @param array $meta | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
string $name, | ||
string $primaryFieldName, | ||
string $requestFieldName, | ||
\Packetery\Checkout\Model\ResourceModel\Order\CollectionFactory $collectionFactory, | ||
\Magento\Sales\Model\OrderFactory $orderFactory, | ||
array $meta = [], | ||
array $data = [] | ||
) { | ||
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); | ||
$this->collection = $collectionFactory->create(); | ||
$this->orderFactory = $orderFactory; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getData(): array | ||
{ | ||
$result = []; | ||
|
||
foreach ($this->collection->getItems() as $item) { | ||
$result[$item->getId()]['general'] = $item->getData(); // princing rules | ||
$orderNumber = $result[$item->getId()]['general']['order_number']; | ||
$order = $this->orderFactory->create()->loadByIncrementId($orderNumber); | ||
|
||
$shippingAddress = $order->getShippingAddress(); | ||
if ($shippingAddress) { | ||
$result[$item->getId()]['general']['misc']['country_id'] = $shippingAddress->getCountryId(); | ||
} else { | ||
$result[$item->getId()]['general']['misc']['country_id'] = null; | ||
} | ||
|
||
$shippingMethod = $order->getShippingMethod(true); | ||
if ($shippingMethod) { | ||
$result[$item->getId()]['general']['misc']['method'] = $shippingMethod->getData('method'); | ||
} else { | ||
$result[$item->getId()]['general']['misc']['method'] = null; | ||
} | ||
} | ||
|
||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceContainer name="js"> | ||
<block class="Packetery\Checkout\Block\Adminhtml\DefaultJs" name="packetery_default_js"/> | ||
</referenceContainer> | ||
</body> | ||
</page> |
12 changes: 12 additions & 0 deletions
12
Packetery/Checkout/view/adminhtml/layout/packetery_order_detail.xml
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,12 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<head> | ||
<script src="https://widget.packeta.com/v6/www/js/library.js" src_type="url" /> | ||
</head> | ||
|
||
<body> | ||
<referenceContainer name="content"> | ||
<uiComponent name="packetery_order_detail_form"/> | ||
</referenceContainer> | ||
</body> | ||
</page> |
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,10 @@ | ||
<?php | ||
/** @var \Packetery\Checkout\Block\Adminhtml\DefaultJs $block */ | ||
?> | ||
|
||
<script> | ||
require([], function () { | ||
window.packetery = window.packetery || {}; | ||
window.packetery.baseUrl = '<?= /** @noEscape */ $block->getBaseUrl(); ?>'; | ||
}); | ||
</script> |
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
Oops, something went wrong.