Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Barcode Mod...
 
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features
 
Thread Tools Search this Thread
  #1  
Old 03-21-2007, 05:12 AM
 
kevinrm kevinrm is online now
 

X-Adept
  
Join Date: Aug 2003
Posts: 904
 

Lightbulb Barcode Mod...

My first mod: 3 of 9 barcode insertion into the html invoices. I didn't write the actual barcode script, I found that on the web. Somehow I managed to piece it all together and make it print out the SKU barcode on the html invoice. This should save a lot of time on data entry.

1) Copy the barcode script found here: http://www.sid6581.net/cs/php-scripts/barcode/ and paste into your root directory. Here is the actual code:

<?php
/*================================================= ==========================*/
/* PHP Barcode Image Generator v1.0 [9/28/2000]
Copyright (C)2000 by Charles J. Scheffold - cs@sid6581.net


---
UPDATE 5/10/2005 by C.Scheffold
Changed FontHeight to -2 if no text is to be displayed (this eliminates
the whitespace at the bottom of the image)
---
UPDATE 03/12/2005 by C.Scheffold
Added '-' character to translation table
---
UPDATE 09/21/2002 by Laurent NAVARRO - ln@altidev.com - http://www.altidev.com
Updated to be compatible with register_globals = off and on
---
UPDATE 4/6/2001 - Important Note! This script was written with the assumption
that "register_globals = On" is defined in your PHP.INI file! It will not
work as-is and as described unless this is set. My PHP came with this
enabled by default, but apparently many people have turned it off. Either
turn it on or modify the startup code to pull the CGI variables in the old
fashioned way (from the HTTP* arrays). If you just want to use the functions
and pass the variables yourself, well then go on with your bad self.
---

This code is hereby released into the public domain.
Use it, abuse it, just don't get caught using it for something stupid.


The only barcode type currently supported is Code 3 of 9. Don't ask about
adding support for others! This is a script I wrote for my own use. I do
plan to add more types as time permits but currently I only require
Code 3 of 9 for my purposes. Just about every scanner on the market today
can read it.


PARAMETERS:
-----------
$barcode = [required] The barcode you want to generate


$type = (default=0) It's 0 for Code 3 of 9 (the only one supported)

$width = (default=160) Width of image in pixels. The image MUST be wide
enough to handle the length of the given value. The default
value will probably be able to display about 6 digits. If you
get an error message, make it wider!


$height = (default=80) Height of image in pixels

$format = (default=jpeg) Can be "jpeg", "png", or "gif"

$quality = (default=100) For JPEG only: ranges from 0-100


$text = (default=1) 0 to disable text below barcode, >=1 to enable


NOTE: You must have GD-1.8 or higher compiled into PHP
in order to use PNG and JPEG. GIF images only work with
GD-1.5 and lower. (http://www.boutell.com)


ANOTHER NOTE: If you actually intend to print the barcodes
and scan them with a scanner, I highly recommend choosing
JPEG with a quality of 100. Most browsers can't seem to print
a PNG without mangling it beyond recognition.


USAGE EXAMPLES FOR ANY PLAIN OLD HTML DOCUMENT:
-----------------------------------------------


<IMG SRC="barcode.php?barcode=HELLO&quality=75">


<IMG SRC="barcode.php?barcode=123456&width=320&height=2 00">


*/
/*================================================= ============================*/


//-----------------------------------------------------------------------------
// Startup code
//-----------------------------------------------------------------------------


if(isset($_GET["text"])) $text=$_GET["text"];
if(isset($_GET["format"])) $format=$_GET["format"];
if(isset($_GET["quality"])) $quality=$_GET["quality"];
if(isset($_GET["width"])) $width=$_GET["width"];
if(isset($_GET["height"])) $height=$_GET["height"];
if(isset($_GET["type"])) $type=$_GET["type"];
if(isset($_GET["barcode"])) $barcode=$_GET["barcode"];




if (!isset ($text)) $text = 1;
if (!isset ($type)) $type = 1;
if (empty ($quality)) $quality = 100;
if (empty ($width)) $width = 160;
if (empty ($height)) $height = 80;
if (!empty ($format)) $format = strtoupper ($format);
else $format="PNG";


switch ($type)
{
default:
$type = 1;
case 1:
Barcode39 ($barcode, $width, $height, $quality, $format, $text);
break;
}


//-----------------------------------------------------------------------------
// Generate a Code 3 of 9 barcode
//-----------------------------------------------------------------------------
function Barcode39 ($barcode, $width, $height, $quality, $format, $text)
{
switch ($format)
{
default:
$format = "JPEG";
case "JPEG":
header ("Content-type: image/jpeg");
break;
case "PNG":
header ("Content-type: image/png");
break;
case "GIF":
header ("Content-type: image/gif");
break;
}


$im = ImageCreate ($width, $height)
or die ("Cannot Initialize new GD image stream");
$White = ImageColorAllocate ($im, 255, 255, 255);
$Black = ImageColorAllocate ($im, 0, 0, 0);
//ImageColorTransparent ($im, $White);
ImageInterLace ($im, 1);



$NarrowRatio = 20;
$WideRatio = 55;
$QuietRatio = 35;


$nChars = (strlen($barcode)+2) * ((6 * $NarrowRatio) + (3 * $WideRatio) + ($QuietRatio));
$Pixels = $width / $nChars;
$NarrowBar = (int)(20 * $Pixels);
$WideBar = (int)(55 * $Pixels);
$QuietBar = (int)(35 * $Pixels);


$ActualWidth = (($NarrowBar * 6) + ($WideBar*3) + $QuietBar) * (strlen ($barcode)+2);

if (($NarrowBar == 0) || ($NarrowBar == $WideBar) || ($NarrowBar == $QuietBar) || ($WideBar == 0) || ($WideBar == $QuietBar) || ($QuietBar == 0))
{
ImageString ($im, 1, 0, 0, "Image is too small!", $Black);
OutputImage ($im, $format, $quality);
exit;
}

$CurrentBarX = (int)(($width - $ActualWidth) / 2);
$Color = $White;
$BarcodeFull = "*".strtoupper ($barcode)."*";
settype ($BarcodeFull, "string");

$FontNum = 3;
$FontHeight = ImageFontHeight ($FontNum);
$FontWidth = ImageFontWidth ($FontNum);
if ($text != 0)
{
$CenterLoc = (int)(($width-1) / 2) - (int)(($FontWidth * strlen($BarcodeFull)) / 2);
ImageString ($im, $FontNum, $CenterLoc, $height-$FontHeight, "$BarcodeFull", $Black);
}
else

2) In /mail/html/order_data.tpl, replace:

<td align="center">{$product.productcode}</td>
<td><font style="FONT-SIZE: 11px">{$product.product}</font>

with:

{* Mod Begin *}
<td align="center">{$product.productcode}</td>
<td><font style="FONT-SIZE: 11px">{$product.product}<br><IMG SRC="../../barcode.php?barcode={$product.productcode}&width=2 00&height=20&quality=100&text=0"></font>
{* mod end *}

Notes:

1) This works in 4.1.6.

2) My xcart is in my root directory. You may need to adjust the "../../barcode.php?....." part of the file to match your structure.

3) If you get an "image too small" error in the invoice, increase the width of the image.
__________________
X-Cart 5.3.5.4 Live
PHP7.0.16
FPM/FastCGI - enabled
10.1.30-MariaDB
Apache 2.4.29
CENTOS 6.8 64Bit Single Quad-Core E3-1241v3 3.4Ghz 8M 1600 w/ HT
32GB RAM 2x 512GB Samsung 850 Pro SSD RAID 1
Reply With Quote

The following user thanks kevinrm for this useful post:
seyfin (04-25-2016)
  #2  
Old 06-16-2009, 11:49 AM
 
RKs RKs is offline
 

Newbie
  
Join Date: Apr 2008
Posts: 1
 

Default Re: Barcode Mod...

I installed everything according to what you suggested , when I print the
invoice I get an x image instead of the barcode.
__________________
X-cart 4.1.9
Reply With Quote
  #3  
Old 11-22-2011, 03:36 AM
 
Blank Clothing Blank Clothing is offline
 

Newbie
  
Join Date: Nov 2011
Posts: 1
 

Default Re: Barcode Mod...

Thanks kevinrm

I followed the instruction below to barcode the order number for each invoice customer's invoice.

Cheers

BCA
__________________
BCA
www.blankclothing.com.au
Reply With Quote
  #4  
Old 04-22-2016, 07:22 AM
  pauldodman's Avatar 
pauldodman pauldodman is offline
 

X-Man
  
Join Date: Jul 2003
Location: Spain / UK
Posts: 2,925
 

Default Re: Barcode Mod...

Would you believe this still works!!!
Just added it to a 4.7.5 site, with order ID as well as products!
__________________
Paul Dodman
e-business & m-commerce consultant
w: www.luminointernet.com
e: xcart@luminointernet.com

Need help with the latest security patch - click here

Google reCaptcha module for X-Cart now available - Click here

Professional X-Cart help, advice, support and services, specialists in Mobile X-Cart.
Reply With Quote

The following 3 users thank pauldodman for this useful post:
cherie (04-22-2016), qualiteam (04-24-2016), seyfin (04-25-2016)
  #5  
Old 06-29-2017, 05:19 AM
 
GMarler GMarler is offline
 

Advanced Member
  
Join Date: Aug 2005
Location: Western NC USA
Posts: 95
 

Default Re: Barcode Mod...

Quote:
Originally Posted by kevinrm
My first mod: 3 of 9 barcode insertion into the html invoices. I didn't write the actual barcode script, I found that on the web. Somehow I managed to piece it all together and make it print out the SKU barcode on the html invoice. This should save a lot of time on data entry.

1) Copy the barcode script found here: http://www.sid6581.net/cs/php-scripts/barcode/ and paste into your root directory. Here is the actual code:

<?php
/*================================================= ==========================*/
/* PHP Barcode Image Generator v1.0 [9/28/2000]
Copyright (C)2000 by Charles J. Scheffold - cs@sid6581.net


---
UPDATE 5/10/2005 by C.Scheffold
Changed FontHeight to -2 if no text is to be displayed (this eliminates
the whitespace at the bottom of the image)
---
UPDATE 03/12/2005 by C.Scheffold
Added '-' character to translation table
---
UPDATE 09/21/2002 by Laurent NAVARRO - ln@altidev.com - http://www.altidev.com
Updated to be compatible with register_globals = off and on
---
UPDATE 4/6/2001 - Important Note! This script was written with the assumption
that "register_globals = On" is defined in your PHP.INI file! It will not
work as-is and as described unless this is set. My PHP came with this
enabled by default, but apparently many people have turned it off. Either
turn it on or modify the startup code to pull the CGI variables in the old
fashioned way (from the HTTP* arrays). If you just want to use the functions
and pass the variables yourself, well then go on with your bad self.
---

This code is hereby released into the public domain.
Use it, abuse it, just don't get caught using it for something stupid.


The only barcode type currently supported is Code 3 of 9. Don't ask about
adding support for others! This is a script I wrote for my own use. I do
plan to add more types as time permits but currently I only require
Code 3 of 9 for my purposes. Just about every scanner on the market today
can read it.


PARAMETERS:
-----------
$barcode = [required] The barcode you want to generate


$type = (default=0) It's 0 for Code 3 of 9 (the only one supported)

$width = (default=160) Width of image in pixels. The image MUST be wide
enough to handle the length of the given value. The default
value will probably be able to display about 6 digits. If you
get an error message, make it wider!


$height = (default=80) Height of image in pixels

$format = (default=jpeg) Can be "jpeg", "png", or "gif"

$quality = (default=100) For JPEG only: ranges from 0-100


$text = (default=1) 0 to disable text below barcode, >=1 to enable


NOTE: You must have GD-1.8 or higher compiled into PHP
in order to use PNG and JPEG. GIF images only work with
GD-1.5 and lower. (http://www.boutell.com)


ANOTHER NOTE: If you actually intend to print the barcodes
and scan them with a scanner, I highly recommend choosing
JPEG with a quality of 100. Most browsers can't seem to print
a PNG without mangling it beyond recognition.


USAGE EXAMPLES FOR ANY PLAIN OLD HTML DOCUMENT:
-----------------------------------------------


<IMG SRC="barcode.php?barcode=HELLO&quality=75">


<IMG SRC="barcode.php?barcode=123456&width=320&height=2 00">


*/
/*================================================= ============================*/


//-----------------------------------------------------------------------------
// Startup code
//-----------------------------------------------------------------------------


if(isset($_GET["text"])) $text=$_GET["text"];
if(isset($_GET["format"])) $format=$_GET["format"];
if(isset($_GET["quality"])) $quality=$_GET["quality"];
if(isset($_GET["width"])) $width=$_GET["width"];
if(isset($_GET["height"])) $height=$_GET["height"];
if(isset($_GET["type"])) $type=$_GET["type"];
if(isset($_GET["barcode"])) $barcode=$_GET["barcode"];




if (!isset ($text)) $text = 1;
if (!isset ($type)) $type = 1;
if (empty ($quality)) $quality = 100;
if (empty ($width)) $width = 160;
if (empty ($height)) $height = 80;
if (!empty ($format)) $format = strtoupper ($format);
else $format="PNG";


switch ($type)
{
default:
$type = 1;
case 1:
Barcode39 ($barcode, $width, $height, $quality, $format, $text);
break;
}


//-----------------------------------------------------------------------------
// Generate a Code 3 of 9 barcode
//-----------------------------------------------------------------------------
function Barcode39 ($barcode, $width, $height, $quality, $format, $text)
{
switch ($format)
{
default:
$format = "JPEG";
case "JPEG":
header ("Content-type: image/jpeg");
break;
case "PNG":
header ("Content-type: image/png");
break;
case "GIF":
header ("Content-type: image/gif");
break;
}


$im = ImageCreate ($width, $height)
or die ("Cannot Initialize new GD image stream");
$White = ImageColorAllocate ($im, 255, 255, 255);
$Black = ImageColorAllocate ($im, 0, 0, 0);
//ImageColorTransparent ($im, $White);
ImageInterLace ($im, 1);



$NarrowRatio = 20;
$WideRatio = 55;
$QuietRatio = 35;


$nChars = (strlen($barcode)+2) * ((6 * $NarrowRatio) + (3 * $WideRatio) + ($QuietRatio));
$Pixels = $width / $nChars;
$NarrowBar = (int)(20 * $Pixels);
$WideBar = (int)(55 * $Pixels);
$QuietBar = (int)(35 * $Pixels);


$ActualWidth = (($NarrowBar * 6) + ($WideBar*3) + $QuietBar) * (strlen ($barcode)+2);

if (($NarrowBar == 0) || ($NarrowBar == $WideBar) || ($NarrowBar == $QuietBar) || ($WideBar == 0) || ($WideBar == $QuietBar) || ($QuietBar == 0))
{
ImageString ($im, 1, 0, 0, "Image is too small!", $Black);
OutputImage ($im, $format, $quality);
exit;
}

$CurrentBarX = (int)(($width - $ActualWidth) / 2);
$Color = $White;
$BarcodeFull = "*".strtoupper ($barcode)."*";
settype ($BarcodeFull, "string");

$FontNum = 3;
$FontHeight = ImageFontHeight ($FontNum);
$FontWidth = ImageFontWidth ($FontNum);
if ($text != 0)
{
$CenterLoc = (int)(($width-1) / 2) - (int)(($FontWidth * strlen($BarcodeFull)) / 2);
ImageString ($im, $FontNum, $CenterLoc, $height-$FontHeight, "$BarcodeFull", $Black);
}
else

2) In /mail/html/order_data.tpl, replace:

<td align="center">{$product.productcode}</td>
<td><font style="FONT-SIZE: 11px">{$product.product}</font>

with:

{* Mod Begin *}
<td align="center">{$product.productcode}</td>
<td><font style="FONT-SIZE: 11px">{$product.product}<br><IMG SRC="../../barcode.php?barcode={$product.productcode}&width=2 00&height=20&quality=100&text=0"></font>
{* mod end *}

Notes:

1) This works in 4.1.6.

2) My xcart is in my root directory. You may need to adjust the "../../barcode.php?....." part of the file to match your structure.

3) If you get an "image too small" error in the invoice, increase the width of the image.
kevinrm,
I am interested in implementing the barcode generator on my x-cart 4.4 system.
I went to the download link and got it. Could you tell me what files need to be modified in x-cart to activate the barcode.php script?

Thanks in Advance.
Greg
__________________
Greg Marler
x-Cart Pro version 4.4.4
Gold 4.4.4
Gold 4.7.6 (under construction)
CentOS
Apache 2
Reply With Quote
  #6  
Old 06-30-2017, 02:02 AM
 
kevinrm kevinrm is online now
 

X-Adept
  
Join Date: Aug 2003
Posts: 904
 

Default Re: Barcode Mod...

This was from 2007 and XC4.x It's now 10 years later and I'm on XC5.3.2.x, I can't remember that far back unfortunately. But looking at my old instructions…


2) In /mail/html/order_data.tpl, replace:

<td align="center">{$product.productcode}</td>
<td><font style="FONT-SIZE: 11px">{$product.product}</font>

with:

{* Mod Begin *}
<td align="center">{$product.productcode}</td>
<td><font style="FONT-SIZE: 11px">{$product.product}<br><IMG SRC="../../barcode.php?barcode={$product.productcode}&width=2 00&height=20&quality=100&text=0"></font>
{* mod end *}
__________________
X-Cart 5.3.5.4 Live
PHP7.0.16
FPM/FastCGI - enabled
10.1.30-MariaDB
Apache 2.4.29
CENTOS 6.8 64Bit Single Quad-Core E3-1241v3 3.4Ghz 8M 1600 w/ HT
32GB RAM 2x 512GB Samsung 850 Pro SSD RAID 1
Reply With Quote

The following user thanks kevinrm for this useful post:
GMarler (06-30-2017)
  #7  
Old 06-30-2017, 04:20 AM
 
GMarler GMarler is offline
 

Advanced Member
  
Join Date: Aug 2005
Location: Western NC USA
Posts: 95
 

Default Re: Barcode Mod...

Duh, I don't know how I missed the insertion line in your post. Thanks for taking the time to open my eyes
Greg
__________________
Greg Marler
x-Cart Pro version 4.4.4
Gold 4.4.4
Gold 4.7.6 (under construction)
CentOS
Apache 2
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:35 AM.

   

 
X-Cart forums © 2001-2018