Создать страницу adminhtml с несколькими заказами
Я пытаюсь создать модуль, который будет отображать все выбранные заказы с элементами и промежуточными итогами на пользовательской странице администратора.
Это будет работать так:
- Вы выбираете нужный ордер в сетке ордеров, а затем выбираете мой вариант из выпадающего списка.
- Затем он перенаправляет вас на страницу, где все выбранные заказы обрабатываются один за другим (как на странице печати PDF)
В конце концов это должно выглядеть так но с несколькими заказами /
Но я застрял с прохождением заказов и заказов на Magento\Framework\View\Element\RendererList
поэтому он будет отображать элементы заказа.
Я пытаюсь скопировать функциональность стандартного модуля Magento/Sales.
Это контроллер
namespace Mynamespace\Mymodule\Controller\Adminhtml\Orderprint;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Magento\Backend\App\Action\Context;
use Magento\Ui\Component\MassAction\Filter;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\Registry;
class Index extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction
{
protected $orderManagement;
protected $collectionFactory;
protected $pageFactory;
protected $coreRegistry;
public function __construct(
Context $context,
Filter $filter,
CollectionFactory $collectionFactory,
OrderManagementInterface $orderManagement,
PageFactory $pageFactory,
Registry $coreRegistry
) {
parent::__construct($context, $filter);
$this->collectionFactory = $collectionFactory;
$this->orderManagement = $orderManagement;
$this->pageFactory = $pageFactory;
$this->coreRegistry = $coreRegistry;
}
protected function massAction(AbstractCollection $collection){
$orderIds = array();
if ($collection->count() > 0) {
foreach ($collection as $order){
$orderIds[] = $order->getEntityId();
}
}
$this->coreRegistry->register('order_ids', $orderIds);
$resultPage = $this->pageFactory->create();
$resultPage->addHandle('htmlorder_orderprint_index');
return $resultPage;
}
}
БЛОК:
namespace Mynamespace\Mymodule\Block\Adminhtml\Order;
use Braintree\Exception;
use Magento\Customer\Model\Context;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Block\Items\AbstractItems;
class View extends \Magento\Sales\Block\Order\View
{
protected $_template = 'order/view.phtml';
protected $orderRepositoryInterface;
protected $ordersData = array();
protected $abstractItems;
protected $currentOrder;
public function __construct(\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\App\Http\Context $httpContext,
\Magento\Payment\Helper\Data $paymentHelper,
array $data = [],
OrderRepositoryInterface $orderRepository,
AbstractItems $abstractItems)
{
parent::__construct($context, $registry, $httpContext, $paymentHelper, $data);
$this->orderRepositoryInterface = $orderRepository;
$this->abstractItems = $abstractItems;
}
protected function _prepareLayout()
{
}
public function getOrder()
{
return $this->_coreRegistry->registry('current_order');
}
public function getOrders()
{
return $this->_coreRegistry->registry('order_ids');
}
public function getOrderInfo($orderId)
{
try {
return $this->orderRepositoryInterface->get($orderId);
}catch (Exception $e){
}
}
public function setCurrentOrder($order){
$this->currentOrder= $order;
}
public function getCurrentOrder(){
return $this->currentOrder;
}
public function getItems($order){
return $order->getAllItems();
}
public function getItemHtml($item){
return $this->abstractItems->getItemHtml($item);
}
Xml:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Mynamespace\Mymodule\Block\Adminhtml\Order\View" name="htmlorder.print" template="Mynamespace_Mymodule::order/view.phtml">
<block class="Mynamespace\Mymodule\Block\Adminhtml\Order\View" name="htmlorder_items" template="Mynamespace_Mymodule::order/items.phtml">
<block class="Magento\Framework\View\Element\RendererList" name="htmlorder_items.renderers" as="renderer.list" />
<block class="Mynamespace\Mymodule\Block\Adminhtml\Order\Totals" name="order_totals" template="Mynamespace\Mymodule::order/totals.phtml">
<arguments>
<argument name="label_properties" xsi:type="string">colspan="4" class="mark"</argument>
<argument name="value_properties" xsi:type="string">class="amount"</argument>
</arguments>
<block class="Magento\Tax\Block\Sales\Order\Tax" name="tax" template="Magento_Tax::order/tax.phtml">
<action method="setIsPlaneMode">
<argument name="value" xsi:type="string">1</argument>
</action>
</block>
</block>
</block>
</block>
</referenceContainer>
<block class="Magento\Framework\View\Element\Template" name="additional.product.info" template="Magento_Theme::template.phtml"/>
</body>
Я бы очень признателен за помощь. Спасибо!