我正在使用magento 1.9。我想用escpos-php driver把发票打印到U盘热敏打印机上。我将escpos-php库保存在magento安装的根目录中。在magento的一个自定义模块中,我覆盖了默认的发票,当呈现时是A4 pdf,并且我试图制作一个热敏发票pdf (纸张大小C7)。此文件位于/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);
}
}
?>我现在尝试的是,我想从这个/local/Receipt/Pos/Model/Invoice.php文件访问escpos-php驱动程序的类文件。因此,我将escpos-php驱动程序的自动加载器的绝对路径添加到Invoice.php中的代码中,但它会导致如下所示的警告
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!发布于 2018-04-13 18:42:18
为了让autoload识别你的外部库,你必须遵循magento文件结构。
外部库通常位于/lib/下
在您的模块中,您可以将它们用作
require_once Mage::getBaseDir('lib') . '/Mike42/Escpos/Whatever.php';https://stackoverflow.com/questions/49814685
复制相似问题