I am creating a suborder view page in BackOffice that retrieves data from the customized table. However, I received an error on above topic when I click the view button in my customized grid. Did I write the wrong code?
app/code/MyVendor/SubOrder/Controller/Adminhtml/Order/View.php
<?php
namespace MyVendorSubOrderControllerAdminhtmlOrder;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MyVendorSubOrderModelResourceModelSubOrderCollectionFactory;
use MagentoFrameworkAppActionAction;
class View extends Action
{
/**
* @var PageFactory
*/
protected $resultPageFactory;
/**
* @var CollectionFactory
*/
protected $subOrderCollectionFactory;
/**
* View constructor.
* @param Context $context
* @param PageFactory $resultPageFactory
* @param CollectionFactory $subOrderCollectionFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory,
CollectionFactory $subOrderCollectionFactory
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
$this->subOrderCollectionFactory = $subOrderCollectionFactory;
}
/**
* Load the page defined in view.xml layout file
*
* @return MagentoFrameworkViewResultPage
*/
public function execute()
{
$orderId = $this->getRequest()->getParam('order_id');
var_dump($orderId); die;
$orderCollection = $this->subOrderCollectionFactory->create();
$orderCollection->addFieldToFilter('entity_id', $orderId);
$order = $orderCollection->getFirstItem();
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__('Order #%1', $order->getIncrementId()));
return $resultPage;
}
}
?>
I created an action column for viewing the order details
app/code/MyVendor/SubOrder/view/adminhtml/ui_component/myvendor_suborder_order_listing.xml
<actionsColumn name="actions" class="MyVendorSubOrderUiComponentListingColumnViewAction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="viewUrlPath" xsi:type="string">myvendor_suborder/order/view</item>
<item name="urlEntityParamName" xsi:type="string">order_id</item>
</item>
</argument>
<settings>
<indexField>entity_id</indexField>
</settings>
</actionsColumn>
app/code/MyVendor/SubOrder/Ui/Component/Listing/Column/ViewAction.php
<?php
namespace MyVendorSubOrderUiComponentListingColumn;
use MagentoFrameworkUrlInterface;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoUiComponentListingColumnsColumn;
class ViewAction extends Column
{
/**
* @var UrlInterface
*/
protected $urlBuilder;
/**
* Constructor
*
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param UrlInterface $urlBuilder
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
UrlInterface $urlBuilder,
array $components = [],
array $data = []
) {
$this->urlBuilder = $urlBuilder;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
/**
* Prepare Data Source
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
$fieldName = $this->getData('name');
foreach ($dataSource['data']['items'] as &$item) {
$item[$fieldName]['view'] = [
'href' => $this->urlBuilder->getUrl(
$this->getData('config/viewUrlPath'),
[
$this->getData('config/urlEntityParamName') => $item['entity_id']
]
),
'label' => __('View')
];
}
}
return $dataSource;
}
}