Issues

ZF-11964: Some Zend_Barcode Object adapters denies correct length barcodes

Description

Generating a barcode with a correct length length (for example, a 13-chars ean13 code) returns exception, saying ""1234567890123" should have a length of 13 characters". Even with a "'withChecksum' => false" in the Object options, the checksum is always appended, because of the "_mandatoryChecksum" default option in most of the adapters. I don't understand why this option is set, and I think I should be able to pass a complete ean13 with my own checksum. So, I just commented out the "$this->_mandatoryChecksum = true;" line in Zend_Barcode_Object_Ean13.php.

Comments

Even if I can understand your question, why can't you simply give it: substr($code, 0, 12) and it will append the checksum without problem?

Just because I spend much time understanding why I couldn’t pass a simple and complete ean13, and because this class should have an out-of-the-box functionning.

The out-of-the-box is to provide the text to encode (and only the text to encode) and Zend_Barcode will append (if nececessary but in case of EAN13 it's mandatory) the checksum for you.

Well, but can you tell me why is this param mandatory ? It seems that removing it does not break anything. Or is there a way to deactivate it without altering the class ?

Because it's in the standard (http://en.wikipedia.org/wiki/…). You must have a checksum for an EAN13. It isn't the case for all barcodes. That's why we have 'withChecksum' option. But in case of EAN13, you have '_mandatoryChecksum' that overrides the value of the 'withChecksum' option. Because of the interaction with Zend_Validate_Barcode, we can't provide (today) a complete text with an incorporated checksum to the EAN13 object.

My question is: do you want a documentation with a more complete explanation on this point or the ability to provide the 13 characters?

In fact, any of the solutions would save time :) but maybe, the class could check if the checksum is provided by the barcode string, and remove it itself if necessary.

I understand the blocking with Zend_Validate_Barcode, but if I just remove the _mandatoryChecksum param, the barcode validates successfully. What’s wrong with this?

I can add a check to verify that the provided length is exactly the '_barcodeLength' and in this case not appending the checksum. But this won't be possible to provide a barcode of 5 characters + 1 checksum. Because I have also a '_addLeadingZeros' to complete a partial barcode. And I don't know how to determine if a text to encode is an error, a partial or a complete barcode.

You can of course remove '_mandatoryChecksum' in your copy of the library but I can't do this in ZF library. The problem will be for you for upgrading. The other solution is to extend Zend_Barcode_Object_Ean13 in your own library and to use the 'barcodeNamespace' option. In this case, the upgrade to ZF 1.12 won't be a problem :)

bq. but I can't do this in ZF library

Does this mean the issue can be closed as "Wont' Fix"?