Closed mehdininja closed 3 months ago
Hello @mehdininja
If you wish to generate a unique hexadecimal string as a prefix for your invoice numbers, you can easily achieve this through the J2Store Invoice Number Generator app. Here's a step-by-step guide:
Once you've completed these steps, the invoice numbers will be generated with the specified prefix after each purchase. For a visual guide, you can refer to this instructional video: [Video link]
Hello, I like this method : Edit => administrator/components/com_j2store/tables/order.php
public function generateInvoiceNumber ()
{
if ( empty( $this->order_id ) ) return;
$db = JFactory::getDbo ();
$unique = false;
while (!$unique) {
$invoice_number =
strtoupper(
str_pad(dechex(rand(0, 255)), 2, '0', STR_PAD_LEFT) .
str_pad(dechex(rand(0, 255)), 2, '0', STR_PAD_LEFT) .
str_pad(dechex(rand(0, 255)), 2, '0', STR_PAD_LEFT)
);
$query = $db->getQuery(true)
->select('COUNT(invoice_number)')
->from($db->quoteName('#__j2store_orders'))
->where($db->quoteName('invoice_number') . ' = ' . $db->quote($invoice_number));
$db->setQuery($query);
$count = $db->loadResult();
if ($count == 0) {
$unique = true;
$this->invoice_number = $invoice_number;
}
}
$order = $this;
J2Store::plugin ()->event ( 'AfterGenerateInvoiceNumber', array(&$order) );
}
Sample invoice number: A48C92 512AC7 9F3C30
@mehdininja I understand your concern. Typically, if a user wishes to generate an invoice number according to their preferences, we would recommend using an invoice generator app. If you prefer generating an invoice number as a hexadecimal value using custom code, we do not recommend making changes directly to the core files. Instead, you can utilize our custom code app. You can find this app at the file path /plugins/j2store/app_customcode/app_customcode.php. Within this file, you can write your custom function. After implementing this, if your custom code works as intended, you can proceed with it. It will not affect your core code files.
Here is the download link for custom-code App [link]
@mgopin3 how to add generateInvoiceNumber () to app_customcode.php ?
@mehdininja Currently, we are offering J2Store 4.x.x free of charge, which restricts us from engaging in custom development. Additionally, we have not tested the custom generateInvoiceNumber code modifications in the local environment provided by you. Should you wish to implement this, we suggest engaging a third-party developer. You can locate the application at the file path within your backend code: /plugins/j2store/app_customcode/app_customcode.php. Within this file, you can integrate your custom function. Once successful implementation and validation of your custom code have been completed, you may proceed with confidence, assured that it will not impact your core code files.
@mehdininja We believe the reported issue has been addressed. Could you please confirm that the problem is resolved on your end? If everything looks good, we'll go ahead and close this issue.
If you have any further questions or if there's anything else you'd like assistance with, please don't hesitate to let us know. We appreciate your feedback!
hi The invoice number is AUTO_INCREMENT, I want the invoice number to be generated as a random hexadecimal string, Which files should I edit?