- Posts: 76
- Thank you received: 2
Custom field to generate random number
- jberry210490
-
Topic Author
- Offline
Less
More
3 years 7 months ago #348863
by jberry210490
Custom field to generate random number was created by jberry210490
-- HikaShop version -- : 4.5.0
-- Joomla version -- : 4.1.5
-- PHP version -- : 7.4.33
Hi guys,
i need to set up a custom field which would generate random 4 numbers which i'd later show in the invoice.
I'd set it up in the Order table but the question is, is it possible to use the custom text field type to use php code which will generate the random number for me or there's another way to do it?
cheers
-- Joomla version -- : 4.1.5
-- PHP version -- : 7.4.33
Hi guys,
i need to set up a custom field which would generate random 4 numbers which i'd later show in the invoice.
I'd set it up in the Order table but the question is, is it possible to use the custom text field type to use php code which will generate the random number for me or there's another way to do it?
cheers
Please Log in or Create an account to join the conversation.
3 years 7 months ago #348866
by nicolas
Replied by nicolas on topic Custom field to generate random number
Hi,
You can create a mass action with a trigger "after an order is created" with an action "update the values" on the column of your custom field with the mode "operation" and some MySQL commands to generate the number. Several propositions are presented here:
stackoverflow.com/questions/3964624/how-...igit-number-in-mysql
I suppose I would try something like that:
Otherwise, if you update your HikaShop, you'll have the "run PHP code" action in mass actions, and you can do it with PHP code like this:
where xxx is the column of your custom field.
You can create a mass action with a trigger "after an order is created" with an action "update the values" on the column of your custom field with the mode "operation" and some MySQL commands to generate the number. Several propositions are presented here:
stackoverflow.com/questions/3964624/how-...igit-number-in-mysql
I suppose I would try something like that:
Code:
LPAD(FLOOR(RAND()*10000),4,'0')
Code:
$order = new stdClass();
$order->order_id = {order_id};
$order->xxx = rand ( 1000 , 9999 );
$class = hikashop_get('class.order');
$class->save($order);
Please Log in or Create an account to join the conversation.
Time to create page: 0.182 seconds