Jump to content

Extending ean13 for magazines


irrelevant

Recommended Posts

Here in the UK at least, magazines often have the same ean13 barcode for all issues, which causes me problems when I want to list different ones!  The printed barcode has a supplemental 2 digit issue number following it, so it seems sensible to allow for that.

 

The following changes allow for entry of an ean13 in the form 1234567890123.12, i.e. appending a period and a two digit number.  This does for me, although I realise that it might break modules that use the ean13.

 

First, extend the field in the database via your favourite SQL access.





ALTER TABLE `ps_product` CHANGE COLUMN `ean13` `ean13` VARCHAR(16);

Create these files:

./override/classes/Product.php







<?php

class Product extends ProductCore

{



public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)

{

self::$definition['fields']['ean13']['size'] = 16;

parent::__construct($id_product, $full, $id_lang, $id_shop, $context);

}

}

./override/classes/Validate.php







<?php
class Validate extends ValidateCore

{

public static function isEan13($ean13)

{

return !$ean13 || preg_match('/^[0-9]{0,13}$/', $ean13) || preg_match('/^[0-9]{0,13}\.[0-9][0-9]$/', $ean13);

}

}

Copy file ADMINFOLDER/themes/default/template/controllers/product/information.php

to

/override/controllers/admin/templates/products/information.php  (you may have to create the products folder.)

then edit it, look for





<input maxlength="13" type="text" id="ean13" name="ean13" value="{$product->ean13|htmlentitiesUTF8}" />

and alter the maxlength to 16

 

(Why this doesn't get the length from the field definition I do not know...)

 

That should be it.   Hope this helps somebody else...

 

 

Link to comment
Share on other sites

  • 8 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...