bebeboutik/modules/barcodes/barcodes.php

43 lines
1.4 KiB
PHP
Raw Normal View History

2016-01-04 12:49:26 +01:00
<?php
if(!defined('_PS_VERSION_')) {
exit;
}
class Barcodes extends Module {
public $_html = '';
function __construct() {
$this->name = 'barcodes';
$this->tab = 'shipping_logistics';
$this->version = '1.0';
$this->author = 'Antadis';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Barcodes');
$this->description = $this->l('Allows to generate barcodes in Prestashop');
}
public function install() {
return parent::install() && $this->registerHook('PDFInvoice');
}
public function hookPDFInvoice($params) {
require_once dirname(__FILE__).'/php-barcode-2.0.1.php';
$str = 'O-'.$params['id_order'].' ';
$width = 860;
$height = 300;
$im = imagecreatetruecolor($width, $height);
$black = ImageColorAllocate($im, 0x00, 0x00, 0x00);
$white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
imagefilledrectangle($im, 0, 0, $width, $height, $white);
Barcode::gd($im, $black, $width / 2, $height / 2, 0, "code39", $str, 5, 150);
imagettftext($im, 30, 0, $width / 2 - (strlen('* '.str_replace(' ', '', $str).' *') * 11), $height - 25, $black, dirname(__FILE__).'/MODENINE.TTF', '* '.str_replace(' ', '', $str).' *');
imagegif($im, dirname(__FILE__).'/codes/O-'.$params['id_order'].'.gif');
$params['pdf']->Image(dirname(__FILE__).'/codes/O-'.$params['id_order'].'.gif', 130, 234, 0, 19, 'GIF');
}
}