Printing 为来宾Magento启用打印订单功能

Printing 为来宾Magento启用打印订单功能,printing,checkout,magento-1.9,Printing,Checkout,Magento 1.9,我需要为客人结账启用打印订单功能 对于已登录的用户,打印功能工作正常 但对于来宾用户,打印按钮在成功页面上不可见 要显示打印按钮,我已删除签入文件success.phtml 但我不明白如何使打印功能,客人没有登录可用。 请提前向我表示感谢您应该尝试此扩展:它工作得非常好,是一种节省的方式,可以在客人结账后提供订单确认的打印链接。在Magento 2中: 您必须覆盖模块Sales,然后覆盖以下2个控制器,如下所示: app/code/YourVendorName/Sales/etc/di.xml

我需要为客人结账启用打印订单功能

对于已登录的用户,打印功能工作正常

但对于来宾用户,打印按钮在成功页面上不可见 要显示打印按钮,我已删除签入文件success.phtml

但我不明白如何使打印功能,客人没有登录可用。
请提前向我表示感谢

您应该尝试此扩展:它工作得非常好,是一种节省的方式,可以在客人结账后提供订单确认的打印链接。

在Magento 2中: 您必须覆盖模块Sales,然后覆盖以下2个控制器,如下所示:

app/code/YourVendorName/Sales/etc/di.xml

 <preference for="Magento\Sales\Controller\Order\PrintAction" type="YourVendorNAme\Sales\Controller\Order\PrintAction"/>
<preference for="Magento\Sales\Controller\AbstractController\OrderLoader" type="YourVendorNAme\Sales\Controller\AbstractController\OrderLoader"/>

app/code/YourVendorName/Sales/Controller/AbstractController/OrderLoader.php

    <?php
namespace YourVendorNAme\Sales\Controller\AbstractController;

use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\Forward;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Registry;
use Magento\Framework\Controller\Result\ForwardFactory;
use Magento\Framework\Controller\Result\RedirectFactory;

class OrderLoader implements \Magento\Sales\Controller\AbstractController\OrderLoaderInterface
{
    /**
     * @var \Magento\Sales\Model\OrderFactory
     */
    protected $orderFactory;

    /**
     * @var \Magento\Framework\Registry
     */
    protected $registry;

    /**
     * @var \Magento\Sales\Controller\AbstractController\OrderViewAuthorizationInterface
     */
    protected $orderAuthorization;

    /**
     * @var \Magento\Framework\UrlInterface
     */
    protected $url;

    /**
     * @var ForwardFactory
     */
    protected $resultForwardFactory;

    /**
     * @var RedirectFactory
     */
    protected $redirectFactory;

    private $checkoutSession;

    /**
     * @param \Magento\Sales\Model\OrderFactory $orderFactory
     * @param OrderViewAuthorizationInterface $orderAuthorization
     * @param Registry $registry
     * @param \Magento\Framework\UrlInterface $url
     * @param ForwardFactory $resultForwardFactory
     * @param RedirectFactory $redirectFactory
     */
    public function __construct(
        \Magento\Sales\Model\OrderFactory $orderFactory,
        \Magento\Sales\Controller\AbstractController\OrderViewAuthorizationInterface $orderAuthorization,
        Registry $registry,
        \Magento\Framework\UrlInterface $url,
        ForwardFactory $resultForwardFactory,
        RedirectFactory $redirectFactory,
        \Magento\Checkout\Model\Session $checkoutSession

    ) {
        $this->orderFactory = $orderFactory;
        $this->orderAuthorization = $orderAuthorization;
        $this->registry = $registry;
        $this->url = $url;
        $this->resultForwardFactory = $resultForwardFactory;
        $this->redirectFactory = $redirectFactory;
        $this->checkoutSession = $checkoutSession;

    }

    /**
     * @param RequestInterface $request
     * @return bool|Forward|Redirect
     */
    public function load(RequestInterface $request)
    {
        $orderId = (int)$request->getParam('order_id');
        if (!$orderId) {
            /** @var Forward $resultForward */
            $resultForward = $this->resultForwardFactory->create();
            return $resultForward->forward('noroute');
        }

        $order = $this->orderFactory->create()->load($orderId);
        $lastOrderId = $this->checkoutSession->getData('last_order_id');

        // Print order if customer is logged in or it's the last order of guest customer
        if ($this->orderAuthorization->canView($order) || $lastOrderId == $orderId) {
            $this->registry->register('current_order', $order);
            return true;
        }

        /** @var Redirect $resultRedirect */
        $resultRedirect = $this->redirectFactory->create();
        return $resultRedirect->setUrl($this->url->getUrl('*/*/history'));
    }
}

M2怎么样?我不知道。我不再喜欢Magento了。
 <preference for="Magento\Sales\Controller\Order\PrintAction" type="YourVendorNAme\Sales\Controller\Order\PrintAction"/>
<preference for="Magento\Sales\Controller\AbstractController\OrderLoader" type="YourVendorNAme\Sales\Controller\AbstractController\OrderLoader"/>
    <?php
namespace YourVendorNAme\Sales\Controller\AbstractController;

use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\Forward;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Registry;
use Magento\Framework\Controller\Result\ForwardFactory;
use Magento\Framework\Controller\Result\RedirectFactory;

class OrderLoader implements \Magento\Sales\Controller\AbstractController\OrderLoaderInterface
{
    /**
     * @var \Magento\Sales\Model\OrderFactory
     */
    protected $orderFactory;

    /**
     * @var \Magento\Framework\Registry
     */
    protected $registry;

    /**
     * @var \Magento\Sales\Controller\AbstractController\OrderViewAuthorizationInterface
     */
    protected $orderAuthorization;

    /**
     * @var \Magento\Framework\UrlInterface
     */
    protected $url;

    /**
     * @var ForwardFactory
     */
    protected $resultForwardFactory;

    /**
     * @var RedirectFactory
     */
    protected $redirectFactory;

    private $checkoutSession;

    /**
     * @param \Magento\Sales\Model\OrderFactory $orderFactory
     * @param OrderViewAuthorizationInterface $orderAuthorization
     * @param Registry $registry
     * @param \Magento\Framework\UrlInterface $url
     * @param ForwardFactory $resultForwardFactory
     * @param RedirectFactory $redirectFactory
     */
    public function __construct(
        \Magento\Sales\Model\OrderFactory $orderFactory,
        \Magento\Sales\Controller\AbstractController\OrderViewAuthorizationInterface $orderAuthorization,
        Registry $registry,
        \Magento\Framework\UrlInterface $url,
        ForwardFactory $resultForwardFactory,
        RedirectFactory $redirectFactory,
        \Magento\Checkout\Model\Session $checkoutSession

    ) {
        $this->orderFactory = $orderFactory;
        $this->orderAuthorization = $orderAuthorization;
        $this->registry = $registry;
        $this->url = $url;
        $this->resultForwardFactory = $resultForwardFactory;
        $this->redirectFactory = $redirectFactory;
        $this->checkoutSession = $checkoutSession;

    }

    /**
     * @param RequestInterface $request
     * @return bool|Forward|Redirect
     */
    public function load(RequestInterface $request)
    {
        $orderId = (int)$request->getParam('order_id');
        if (!$orderId) {
            /** @var Forward $resultForward */
            $resultForward = $this->resultForwardFactory->create();
            return $resultForward->forward('noroute');
        }

        $order = $this->orderFactory->create()->load($orderId);
        $lastOrderId = $this->checkoutSession->getData('last_order_id');

        // Print order if customer is logged in or it's the last order of guest customer
        if ($this->orderAuthorization->canView($order) || $lastOrderId == $orderId) {
            $this->registry->register('current_order', $order);
            return true;
        }

        /** @var Redirect $resultRedirect */
        $resultRedirect = $this->redirectFactory->create();
        return $resultRedirect->setUrl($this->url->getUrl('*/*/history'));
    }
}
    <?php

namespace YourVendorNAme\Sales\Controller\Order;

use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\View\Result\Page;
use Magento\Sales\Controller\OrderInterface;

class PrintAction extends \Magento\Sales\Controller\AbstractController\PrintAction implements OrderInterface
{
    /**
     * @return ResponseInterface|ResultInterface|Page
     */
    public function execute()
    {
        $result = $this->orderLoader->load($this->_request);
        if ($result instanceof ResultInterface) {
            return $result;
        }

        /** @var Page $resultPage */
        $resultPage = $this->resultPageFactory->create();
        $resultPage->addHandle('print');
        return $resultPage;
    }
}