【问题标题】:Enable print order functionality for guest Magento为访客 Magento 启用打印订单功能
【发布时间】:2014-07-10 05:24:35
【问题描述】:

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

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

但对于访客用户,打印按钮在成功页面上不可见 要显示打印按钮,我已删除文件 success.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;?>

现在客人也可以看到打印按钮,但是当我点击时 它要求登录。

我也需要在没有登录的情况下显示访客的打印顺序。

打印订单位置是这样的

localhost/magento1.9/index.php/sales/order/print/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();
}

但我不明白如何在未登录的情况下为访客提供打印功能。 请建议我提前谢谢

【问题讨论】:

    标签: printing checkout magento-1.9


    【解决方案1】:

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

    【讨论】:

    • M2怎么样?
    • 我不知道。我不再喜欢 Magento。
    【解决方案2】:

    在 Magento 2 中: 您必须覆盖模块销售,然后像这样覆盖以下 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'));
        }
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 2019-05-01
      相关资源
      最近更新 更多