首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在magento中添加escpos-php?

如何在magento中添加escpos-php?
EN

Stack Overflow用户
提问于 2018-04-13 18:18:08
回答 1查看 105关注 0票数 0

我正在使用magento 1.9。我想用escpos-php driver把发票打印到U盘热敏打印机上。我将escpos-php库保存在magento安装的根目录中。在magento的一个自定义模块中,我覆盖了默认的发票,当呈现时是A4 pdf,并且我试图制作一个热敏发票pdf (纸张大小C7)。此文件位于/local/Receipt/Pos/Model/Invoice.php

代码语言:javascript
复制
<?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);

         }
    }
   ?>

我现在尝试的是,我想从这个/local/Receipt/Pos/Model/Invoice.php文件访问escpos-php驱动程序的类文件。因此,我将escpos-php驱动程序的自动加载器的绝对路径添加到Invoice.php中的代码中,但它会导致如下所示的警告

代码语言:javascript
复制
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!
EN

回答 1

Stack Overflow用户

发布于 2018-04-13 18:42:18

为了让autoload识别你的外部库,你必须遵循magento文件结构。

外部库通常位于/lib/下

在您的模块中,您可以将它们用作

代码语言:javascript
复制
require_once Mage::getBaseDir('lib') . '/Mike42/Escpos/Whatever.php';
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49814685

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档