0

I am working with magento 1.9. I want to use the escpos-php driver to print our invoices to the usb thermal printer. I have kept the escpos-php libraries in the root directory of my magento installation. In a custom module of magento, I have overwritten the default invoices which was A4 pdf when rendered and I tried to make a thermal invoice pdf (paper size C7). This file exists at /local/Receipt/Pos/Model/Invoice.php

<?php
  class Receipt_Pos_Model_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice
  {
        public function getPdf($invoices = array())
        {
            // I want to access the libraries from here in this 
            // function like shown  below. where 'vendor' is a directory
            // created by myself.
            require(Mage::getBaseDir('lib') .'/vendor/mike42/escpos-php/autoload.php'); // this is the autoloader that comes with escpos-php driver.
            use Mike42\Escpos\PrintConnectors\FilePrintConnector; // Warning is raised at this line.
            use Mike42\Escpos\Printer;
            $connector = new FilePrintConnector("/dev/usb/lp0");
            $printer = new Printer($connector);

         }
    }
   ?>

What am I trying now is, I want to access the class files of the escpos-php driver from this /local/Receipt/Pos/Model/Invoice.php file. So I have added the absolute path of the escpos-php driver's autoloader to the code in Invoice.php but it results in a warning like the one below

Warning: include(Mike42\Escpos\PrintConnectors\PrintConnector.php): failed to open stream: No such file or directory  in /var/www/html/checkout/Gama_V2/shop/lib/Varien/Autoload.php on line 94

I think the autoloader of Magento is also trying to find the class files of the escpos-php driver and fails to load it. But I don't want the magento autoloader work here because, I have already included the autoloader of escpos-php driver which takes care of loading its files. How can I avoid this warning and proceed to print receipts? Please help me!
Velu narasimman
  • 543
  • 1
  • 5
  • 18

1 Answers1

0

To make autoload recognize your external library you will have to follow magento file structure.

External Libraries use to be located under /lib/

in your module you may use them as

require_once Mage::getBaseDir('lib') . '/Mike42/Escpos/Whatever.php';
Vladimir Samsonov
  • 1,344
  • 2
  • 11
  • 18
  • yes I tried this out but still getting the same warning! I have no idea. By the way, when I searched online, I found a similar problem unanswered, I present that here for better understanding of the problem. Please refer to [https://stackoverflow.com/questions/14154449/magento-trying-to-autoload-class-unnecessarily] – Velu narasimman Apr 13 '18 at 11:00
  • expose more of your code for review and tell what part of the library you put where in magento. You should consider to use Varien Autoload instead of external one. – Vladimir Samsonov Apr 13 '18 at 11:16