1

What to do to get random number with each invoice apart from invoice number that can be viewed in Admin side Invoices table, customer account view order or invoice pdf?

Whenever any invoice is created, it will have one random number like "3456445354" or "4467575756". It is used to third party verification whether the order is legit or not.

Can anybody help to get this thing?

1

You can add a new attribute to the sales_flat_order_invoice table whith a default value set to a random number. Try something like this, create an upgrade script:

<?php
$this->startSetup();
$connection = $this->getConnection();

$this->addAttribute('sales_flat_order_item', 'random_number', array(
    'label' => 'Random Number',
    'type' => 'varchar',
    'input' => 'text',
    'visible' => true,
    'required' => false,
    'position' => 1,
    'visible_on_front'  => true,
    'default' => 'FLOOR(((CURTIME()+0)*1000000)*RAND())',
));

$this->endSetup();

Then each time a new invoice is generated the new attribute will get a random number generated automatically by Mysql

  • Where do I add this code? So if I see the invoice which was already generated, then it will show the same number which was generated at the first time when that invoice is generated? – hks Jul 16 '15 at 8:17
  • Check this post, jump to the Install Update Script part. It explains how the update scripts work: inchoo.net/magento/… – lloiacono Jul 16 '15 at 8:19
  • Ok. I will check it out and let u know. Thank u so much. – hks Jul 16 '15 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.