Your IP : 216.73.216.220


Current Path : /var/www/html/app/code/FlipsDigital/HappyMind/Block/Textbook/Order/
Upload File :
Current File : /var/www/html/app/code/FlipsDigital/HappyMind/Block/Textbook/Order/Success.php

<?php
namespace FlipsDigital\HappyMind\Block\Textbook\Order;

class Success extends \Magento\Directory\Block\Data
{
    public function __construct(        
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Directory\Helper\Data $directoryHelper,
        \Magento\Framework\Json\EncoderInterface $jsonEncoder,
        \Magento\Framework\App\Cache\Type\Config $configCacheType,
        \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory,
        \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory,
        array $data = [],
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
        \FlipsDigital\EducationInstitution\Model\EducationInstitutionFactory $educationInstitutionFactory,
        \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookListFactory $customerTextbookListFactory,
        \FlipsDigital\TextbookList\Model\TextbookListFactory $textbookListFactory,
        \FlipsDigital\TextbookListBook\Model\TextbookListBookFactory $textbookListBookFactory,
        \FlipsDigital\TextbookListStudent\Model\TextbookListStudentFactory $textbookListStudentFactory,
        \Magento\Framework\ObjectManagerInterface $objectmanager
    ) {
        parent::__construct($context, $directoryHelper, $jsonEncoder, $configCacheType, $regionCollectionFactory, $countryCollectionFactory, $data);
        $this->_objectManager = $objectmanager;
		$this->_eiFactory = $educationInstitutionFactory;
		$this->_ctlFactory = $customerTextbookListFactory;
		$this->_tlFactory = $textbookListFactory;
		$this->_tlbFactory = $textbookListBookFactory;
		$this->_tlsFactory = $textbookListStudentFactory;
        $this->orderRepository = $orderRepository;
    }
    public function getFormattedPrice($price)
    {
        $priceHelper = $this->_objectManager->create(\Magento\Framework\Pricing\Helper\Data::class);
        return $priceHelper->currency($price, true, false);;
    }
    
    public function getCustomerTextbookList()
    {
        $params = $this->getRequest()->getParams();
        $objCTL = $this->_ctlFactory->create();
        $objCustomerTextbookList = null;
        if (!empty($params['id'])) $objCustomerTextbookList = $objCTL->load($params['id']);
        return $objCustomerTextbookList;
    }
    public function getId()
    {
        $params = $this->getRequest()->getParams();
        return isset($params['id'])?$params['id']:"";
    }
    public function getMagentoOrderId()
    {
        $params = $this->getRequest()->getParams();
        return isset($params['magento_order_id'])?$params['magento_order_id']:"";
    }
    public function getPaymentId()
    {
        $params = $this->getRequest()->getParams();
        return isset($params['payment_id'])?$params['payment_id']:"";
    }
    public function getTextbookListKey()
    {
        $params = $this->getRequest()->getParams();
        return isset($params['textbook'])?$params['textbook']:"";
    }
    public function getTextbookListId()
    {
        $params = $this->getRequest()->getParams();
        return isset($params['tid'])?$params['tid']:"";
    }
    public function getTextbookList()
    {
        $objTL = $this->_tlFactory->create();
        $objCustomerTextbookList = $this->getCustomerTextbookList();
        if (!empty($objCustomerTextbookList)){
            $objTextbookList = $objTL->load($objCustomerTextbookList->getData('booklist_id'));
        }elseif (!empty($this->getTextbookListId())){
            $objTextbookList = $objTL->load($this->getTextbookListId());
        }
        return $objTextbookList;
    }
    public function getTextbookListBook()
    {
        $objTLB = $this->_tlbFactory->create();
        $objTextbookList = $this->getTextbookList();
        $collectionTLB = $objTLB->getCollection();
        $collectionTLB->addAttributeToSelect('*');
        $collectionTLB->addAttributeToFilter('booklist_id', $objTextbookList->getId());
        $collectionTLB->addAttributeToFilter('status', 1);
        $collectionTLB->addAttributeToFilter('magento_hidden', 0);
        $collectionTLB->addAttributeToFilter('mers_stock_source_table', ['neq' => 'NULL']);
        $collectionTLB->getSelect()->order(new \Zend_Db_Expr("CASE WHEN `mers_stock_source_table` = 'G_GL_GROUP_BOOKLIST' THEN 1 WHEN `mers_stock_source_table` = 'G_GL_GROUP_OPTION' THEN 2 WHEN `mers_stock_source_table` = 'G_GL_GROUP_MISC' THEN 3 ELSE 4 END"));
        $collectionTLB->setOrder('print_seq','ASC');
        return $collectionTLB->getItems();
    }
    public function getEducationInstitution()
    {
        $objEI = $this->_eiFactory->create();
        $objTextbookList = $this->getTextbookList();
        $objEducationInstitution = $objEI->load($objTextbookList->getData('education_institution_id'));
        return $objEducationInstitution;
    }
    public function getOrderId()
    {
        $objCustomerTextbookList = $this->getCustomerTextbookList();
        return $objCustomerTextbookList->getData('order_id');
    }
    public function getOrderItems()
    {
        $objCustomerTextbookList = $this->getCustomerTextbookList();
        $order = $this->orderRepository->get($objCustomerTextbookList->getData('order_id'));
        $orderItems = [];
        foreach ($order->getAllItems() as $item) {
            $arrData = $item->getData();
            $orderItems[$arrData['product_id']] = $arrData;
        }
        return $orderItems;
    }
    public function getOrderRealOrderId()
    {
        $objCustomerTextbookList = $this->getCustomerTextbookList();
        $order = $this->orderRepository->get($objCustomerTextbookList->getData('order_id'));
        return $order->getRealOrderId();
    }
    public function getOrderGrandTotal()
    {
        $objCustomerTextbookList = $this->getCustomerTextbookList();
        $order = $this->orderRepository->get($objCustomerTextbookList->getData('order_id'));
        return $order->getGrandTotal();
    }
    public function getOrderSubTotal()
    {
        $objCustomerTextbookList = $this->getCustomerTextbookList();
        $order = $this->orderRepository->get($objCustomerTextbookList->getData('order_id'));
        return $order->getSubtotal();
    }
    public function get711Barcode()
    {
        $objCustomerTextbookList = $this->getCustomerTextbookList();
        $order = $this->orderRepository->get($objCustomerTextbookList->getData('order_id'));
        if ($objCustomerTextbookList){
            if (!empty($objCustomerTextbookList->getData('booklist_student_id'))){
                $tlsFactory = $this->_tlsFactory->create();
                $objTLS = $tlsFactory->load($objCustomerTextbookList->getData('booklist_student_id'));
                if ($objTLS){
                    if (!empty($objTLS->getData('mers_stock_source_g_gl_student_barcode711'))){
                        $generator = new \Picqer\Barcode\BarcodeGeneratorPNG();
                        return base64_encode($generator->getBarcode('07202'.$objTLS->getData('mers_stock_source_g_gl_student_barcode711').str_pad(number_format($order->getGrandTotal(), 2, null, '') * 100, 10, "0", STR_PAD_LEFT), $generator::TYPE_CODE_128, 2, 50));
                    }
                }
            }
        }
        return;
    }
    public function getOrderTransactionId()
    {
        $objCustomerTextbookList = $this->getCustomerTextbookList();
        return $objCustomerTextbookList->getData('transaction_id');
    }
    public function getOrderPaymentMethod()
    {
        $objCustomerTextbookList = $this->getCustomerTextbookList();
        return $objCustomerTextbookList->getPaymentMethod();
    }
    public function getOrderPaymentAmount()
    {
        $objCustomerTextbookList = $this->getCustomerTextbookList();
        return $objCustomerTextbookList->getPaymentAmount();
    }
    public function getOrderHandlingCharge()
    {
        $objCustomerTextbookList = $this->getCustomerTextbookList();
        $order = $this->orderRepository->get($objCustomerTextbookList->getData('order_id'));
        return $order->getShippingAmount();
    }
}