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

时间:2014-07-10 05:24:35

标签: printing checkout magento-1.9

  

我需要启用访客结帐的打印订单功能。

     

对于登录用户,打印功能正常运行

     

但是对于访客用户,在成功页面上看不到打印按钮   显示打印按钮我已删除签入文件succcess.phtml

<?php if ($this->getCanViewOrder() && $this->getCanPrintOrder()) :?>
    <p>
        <?php echo $this->__('Click <a href="%s" onclick="this.target=\'_blank\'">here to print</a> a copy of your order confirmation.', $this->getPrintUrl()) ?>
        <?php echo $this->getChildHtml() ?>
    </p>
<?php endif;?>
  

现在打印按钮对于访客也是可见的,但是当我点击时   它要求登录。

     

我还需要在没有登录的情况下显示来宾的打印订单。

打印订单位置就像

本地主机/ magento1.9 / index.php的/销售/订单/打印/ ORDER_ID / 8 /

我查了

  

/var/www/magento1.9/app/code/core/Mage/Sales/Controller/Abstract.php

并找到

的打印操作
public function printAction()
{
    if (!$this->_loadValidOrder()) {
        return;
    }
    $this->loadLayout('print');
    $this->renderLayout();
}

但我无法理解如何在没有登录的情况下为访客提供打印功能。 请提前告知我

2 个答案:

答案 0 :(得分:0)

你应该试试这个扩展名:https://github.com/eltrino/PrintOrder它非常好用,是一种保存方式,可以在客人结账后提供打印链接到订单确认。

答案 1 :(得分:0)

在Magento 2中: 您必须覆盖模块Sales,然后像这样覆盖以下两个Controller:

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'));
    }
}

app / code / YourVendorName / Sales / Controller / Order / PrintAction.php

    <?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;
    }
}