Magento条形码脚本独立

时间:2017-07-13 17:28:39

标签: php image barcode

不久前,一位朋友为我编写了代码,用于生成magento 1中的代码条码。我们在新订单邮件中使用了这些代码。 但令我感到惊讶的是它使用了mage.php ....但是从magento中获取数据还没有任何关系。

以下是代码:

<?php
require_once 'app/Mage.php';
umask(0);
Mage::app();
Mage::app()->loadArea(Mage_Core_Model_App_Area::AREA_FRONTEND);
if( isset($_GET['ord']) && strlen($_GET['ord']) > 5 ) {
    header('Content-Type: image/jpeg');
    $barcodeOptions = array('text' => $_GET['ord']);
    //$rendererOptions = array();
    $rendererOptions = array('imageType' => 'jpeg');
    // Draw the barcode in a new image,
    $imageResource = Zend_Barcode::draw(
        'code39', 'image', $barcodeOptions, $rendererOptions
    );
    imagejpeg($imageResource);

} else { echo "<pre><b>Error:</b> required input not found\n"; }
?>

我在我的交易邮件中使用它,如

<img src="//domain.com/barcode.php?ord={{var order.increment_id}}">

这很有效。但现在我们正在迁移到magento2。 我想将脚本作为独立脚本运行。但是评论前4行不会起作用,因为它表示图像包含错误而无法显示。

我在这里做错了什么或错过了什么?

1 个答案:

答案 0 :(得分:0)

如果你谷歌“PHP条码”你会发现一些脚本和堆栈溢出问题/答案。

之前我使用过http://www.barcodebakery.com/的软件包,它很容易使用,他们在他们的网站上有一个例子。