How could I generate EAN code for existing products and also how could I create automatically this EAN when adding a new product?
On what is this EAN code based on?
Afaik either a product has an EAN or not. You can not just create an EAN. You have to get EANs, so you can put them on your products, you can do this here.