我正在使用magento 1.9。我想使用 escpos-php 驱动程序将我们的发票打印到 USB 热敏打印机。我已经将escpos-php库保存在我的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 Mike42EscposPrintConnectorsFilePrintConnector; // Warning is raised at this line.
use Mike42EscposPrinter;
$connector = new FilePrintConnector("/dev/usb/lp0");
$printer = new Printer($connector);
}
}
?>
我现在正在尝试的是,我想从这个/local/Receipt/Pos/Model/Invoice.php
文件中访问 escpos-php 驱动程序的类文件。所以我在发票中的代码中添加了 escpos-php 驱动程序的自动加载器的绝对路径.php但它会导致如下所示的警告
Warning: include(Mike42EscposPrintConnectorsPrintConnector.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!
要使自动加载识别您的外部库,您必须遵循 magento 文件结构。
外部库通常位于/lib/下
在您的模块中,您可以将它们用作
require_once Mage::getBaseDir('lib') . '/Mike42/Escpos/Whatever.php';