Even Order number format

  • Posts: 171
  • Thank you received: 9
10 years 4 months ago #162109

Hi,

We have multiple vendors, and wants to achieve to main vendor see all the orders.
A problem I've just noticed that all the order numbers are even (dividible by 2). What can cause this?

Example:
We have an order number format:BIF-{id size="5"}/{date format="d/m/Y"}
The order numbers after each other are:
BIF-00002/26/06/2014
BIF-00004/26/06/2014
BIF-00006/26/06/2014
...
but it should be like
BIF-00001/26/06/2014
BIF-00002/26/06/2014
BIF-00003/26/06/2014
etc.

Also wanted to ask, is there a way to modify the automatism of creating invoice number format.
The format is: PO-{id size="5"}/{date format="d/m/Y"}
It's working as always adding +1 to each new order after it has been set to "Approved". Do we have any option/hack to be in relation with ordernumber.

Example:
Now: BIF-00003/26/06/2014 -> PO-00001/26/06/2014 (if this is the firsty approved order)
Should be: BIF-00003/26/06/2014 -> PO-00003/26/06/2014 (the same ID as order number id)

Thanks,
PePe

Last edit: 10 years 4 months ago by pepecortez.

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 4 months ago #162142

Hi,

The order number is based on the order id.
You should see in your database why this number is growing by two. It is possible that you have one sub-sale for the main vendor.

About the invoice number, if you use "{id}" it will use the invoice id and not the order id.
The invoice id is generated when an order is confirmed in order to be sure that there is no hole in the invoice id suite.

Regarding the function " hikashop_encode " which is used to create the order number and invoice number, it is not possible to access to the "order_id" while creating the invoice number.
We will have to check when the function is called, to see if there is the order object is always passed (because we can just pass the order_id or the invoice_id) ; if so, it could be possible to update the function to access to the order_id while creating the invoice number.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 171
  • Thank you received: 9
10 years 3 weeks ago #177642

I had an idea to solve that, but maybe I complicated it too much:

As configuration is set to use the same order_id for sale and subsale as well, I should just solve somehow to load order_id not from the #__hikashop_order table's order_id column, but from a column I added manually.

So I added a new column in phpMyAdmin: 'order_bif_az' with type: int(10)
I created a hikashop plugin, with this content (used history plugin for base):

<?php
class plgHikashopBifupdate extends JPlugin
{
	function plgHikashopBifupdate(&$subject, $config){
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('hikashop', 'bifupdate');
			if(version_compare(JVERSION,'2.5','<')){
				jimport('joomla.html.parameter');
				$this->params = new JParameter($plugin->params);
			} else {
				$this->params = new JRegistry($plugin->params);
			}
		}
	}

	function onAfterOrderCreate(&$order,&$send_email){
		$db = JFactory::getDBO();
		$query = 'UPDATE '.hikashop_table('order').' SET '.hikashop_table('order').'.order_bif_az = (SELECT MAX(order_bif_az)+1) WHERE'.hikashop_table('order').'.order_id = '.$order->order_id.' AND '.hikashop_table('order').'.order_type = SALE;
		$db->setQuery($query);
	}	
}

This should update the freshly created order's order_bif_az row with +1

As it not worked I also tried adding SQL update query to /admin/com_hikashop/helpers/helper.php to around line 256., in function hikashop_encode:
if(is_object($data)){
function hikashop_encode(&$data,$type='order', $format = '') {
	$id = null;
	if(is_object($data)){
		if($type=='order')
		
		$db = JFactory::getDBO();
		$query = 'UPDATE '.hikashop_table('order').' SET '.hikashop_table('order').'.order_bif_az = (SELECT MAX(order_bif_az)+1) WHERE'.hikashop_table('order').'.order_id = '.$data->order_id.' AND '.hikashop_table('order').'.order_type = SALE';
		$db->setQuery($query);
		$id = $data->order_bif_az;
		if($type=='invoice')
			$id = $data->order_invoice_id;
	}

I also changed line from:
$id = $data->order_id;
to
$id = $data->order_bif_az;
nondepending from where the SQL syntax is given (plugin or helper.php).

But update sql is not running on, also $id = $data->order_bif_az is not OK.
Where am I wrong?

Last edit: 10 years 3 weeks ago by pepecortez. Reason: +info

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 3 weeks ago #177664

Hi,

Why not using the invoice number ?
If you change the option "invoice order statuses" in the HikaShop configuration, you can generate the invoice id (and the invoice number) when the order is created ; so you won't have any hole in the system because it is not something managed by the database.
It will do the same you are trying to do ; but it's already implemented in HikaShop.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 171
  • Thank you received: 9
10 years 3 weeks ago #177698

Yeah, that would be a good trick, but...
The mechanism should work this way:
Order number format is: BIF-{id size="5"}/{date format="d/m/Y"}
Invoice number is generated in this format: PO-{order_id size="5"}/{date format="d/m/Y"}

But the main problem, that we MUST give the invoice number just if / when order is APPROVED. And as not all orders are approved we can not let the system to generate it automatically when order is created... :(

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 3 weeks ago #177707

Hi,

Okay ; but because you are using the multi vendor, it creates entries in the order table for the vendor sales. So the "order_id" is growing automatically (by the database increment) and we can't do something special for that.
At least you can duplicate the used code for the "invoice_id" and use it for an another column, which will be use in the hikashop_encode function for the order number.

It is the best I can recommend you ; because the order id is unique for the entire store ; shared between your store and your vendors. There is nothing wrong in that.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 171
  • Thank you received: 9
10 years 3 weeks ago #177748

Yeah, that's clear, that's why I tried to solve my problem this way.

But the main problem is, that the earlier written UPDATE SQL is not running down. I turned on Joomla's built in Debug and Error reporting tool, but in Database checker tab, I can not find my UPDATE method, also I can not see the waited result in phpMyAdmin, in hikashop_order table, so it seems it's not running down.

Why? Can u see anything what is maybe wrong with it, what can cause it's not loaded to run?

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 3 weeks ago #177765

Hi,

Your plugin you wrote should update the "bif" value ; but I recommend you to:
- read the maximum in a single request ; do not try to update the value in the database
- use the onBeforeOrderCreate
- update the value directly in the object ; the order_number is generated using a value that does not exist in the object, because you're just updating the database (and maybe too late regarding when the order number is generated).

Otherwise you will have to re-create the order number yourself in your plugin and it could be a good solution if you want to keep the compatibility with updates :
- get the "bif" value
- create a fake object to call the function hikashop_encode
- get the order_number from the object
- update the object in the database
And you can do that in the afterCreate trigger.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 171
  • Thank you received: 9
10 years 2 weeks ago #177976

Successfully solved by this way, maybe this helps somebody:
in administrator/com_hikashop/helpers/helper.php around line 255.:

if(is_object($data) && ($type=='order')){
	$query_bif = 'SELECT MAX(order_bif_az) FROM '.hikashop_table('order').' WHERE order_id <= '.$data->order_id;
	$db->setQuery($query_bif);
	$bif = $db->loadResult();
	$id = $bif;
}

I created a custom plugin with this content:
<?php
class plgHikashopBifupdate extends JPlugin
{
	function onBeforeOrderCreate(&$order,&$do){
		$db = JFactory::getDBO();
		$rendid = @$order->order_id;
		$ordertype = @$order->order_type;
	
		if ($ordertype == 'sale') {
			$query_null = 'SELECT COUNT(*) FROM '.hikashop_table('order');
			$db->setQuery($query_null);
			$count_null = $db->loadResult();
			if ($count_null == 0){
				$order->order_bif_az = 1;
			}
			else {
				$query_bifaz = 'SELECT (MAX(order_bif_az)+1) FROM '.hikashop_table('order');
				$db->setQuery($query_bifaz);
				$bifaz = $db->loadResult();
				$order->order_bif_az = $bifaz;
			}
		}
	}
	
	function onAfterOrderCreate(&$order,&$do){
		$db = JFactory::getDBO();
		$rendid = @$order->order_id;
		$ordertype = @$order->order_type;
	
		if ($ordertype == 'sale') {
			$query_bifmax = "SELECT MAX(order_bif_az) FROM ".hikashop_table('order');
			$db->setQuery($query_bifmax);
			$bifmax = $db->loadResult();
			
			$query_bifupdate = "UPDATE ".hikashop_table('order')." SET ".hikashop_table('order').".order_bif_az = ".$bifmax." WHERE order_id = ".$rendid ;
			$db->setQuery($query_bifupdate);
			$db->execute($query_bifupdate);	
		}
	}	
}

Thanks for all your help Jerome!

Last edit: 10 years 2 weeks ago by Jerome. Reason: code cleaning
The following user(s) said Thank You: Jerome

Please Log in or Create an account to join the conversation.

Moderators: Obsidev
Time to create page: 0.070 seconds
Powered by Kunena Forum