Your IP : 216.73.216.220


Current Path : /var/www/html/app/code/FlipsDigital/HappyMind/Controller/Order/
Upload File :
Current File : /var/www/html/app/code/FlipsDigital/HappyMind/Controller/Order/PrintAction.php

<?php
namespace FlipsDigital\HappyMind\Controller\Order;

use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;

class PrintAction extends \Magento\Sales\Controller\AbstractController\PrintAction
{
    protected $_coreRegistry = null;
    public function __construct(
        \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookListFactory $customerTextbookListFactory,
        \Magento\Customer\Model\Session $customerSession,
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
        \Magento\Framework\Registry $registry,
        Context $context,
        \Magento\Sales\Controller\AbstractController\OrderLoaderInterface $orderLoader,
        PageFactory $resultPageFactory
    ) {
		$this->_ctlFactory = $customerTextbookListFactory;
        $this->customerSession = $customerSession;
        $this->orderRepository = $orderRepository;
        $this->_coreRegistry = $registry;
        parent::__construct($context, $orderLoader, $resultPageFactory);
    }

    /**
     * Print Order Action
     *
     * @return \Magento\Framework\Controller\ResultInterface
     */
    public function execute()
    {
        $params = $this->getRequest()->getParams();
        if (isset($params['order_id'])){
            $customerId = $this->customerSession->getCustomer()->getId();
            $order = $this->orderRepository->get($params['order_id']);
            if ($order){
                $ctlFactory = $this->_ctlFactory->create();
                $collectionCTL = $ctlFactory->getCollection();
                $collectionCTL->addAttributeToSelect('*')
                        ->addAttributeToFilter('customer_id', $customerId)
                        ->addAttributeToFilter('order_id', $order->getId());
                if ($collectionCTL->count()){
                    if($this->_coreRegistry->registry('current_order')){
                        $this->_coreRegistry->unregister('current_order');
                    }
                    $this->_coreRegistry->register('current_order', $order);
                    $resultPage = $this->resultPageFactory->create();
                    $resultPage->addHandle('happymind_textbook_sales_order_print'); 
                    return $resultPage;
                }
            }
        }
        return parent::execute();
    }
}