Change serial status to used in php?

  • Posts: 98
  • Thank you received: 3
12 years 1 month ago #77626

I want to change the status of a serial to used in my software registration form.

What the best way to do this in php?

Conrad

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

  • Posts: 26166
  • Thank you received: 4029
  • MODERATOR
12 years 1 month ago #77627

Hi,

It would depends.

If you want to do a manual save (without any check) and if you know the serial_id, you can do this:

$serialClass = hikaserial::get('class.serial');
$serial = new stdClass();
$serial->serial_id = $serial_id;
$serial->serial_status = 'used';
$serialClass->save($serial);

Otherwise, you can use the function $serialClass->find($serial_data, $filter = null, $orders = null) if you want to find a serial. The function would return you a list of serial.

There is the function $serialClass->consume($serial_id, $extra_data = null, $check_user = true) to use the consume feature.
The check_user if for checking find only on serial which are assign to the current logged user.
The extra_data is for storing new extra_data information to the serial.

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.
Last edit: 12 years 1 month ago by Jerome. Reason: typo fix

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

  • Posts: 98
  • Thank you received: 3
12 years 1 month ago #77771

Hi Jerome,

This does not work

$serialClass = hikaseriall:get('class.serial');
$serial = new stdClass();
$serial->serial_id = $serial_id;
$serial->serial_status = 'used';
$serialClass->save($serial);

is something mis-spelled?

This does not work

$query = "UPDATE #__hikaserial_serial
SET serial_status = 'used'
WHERE serial_data = '{$serial}'"; //$serial is an input from my form
$database->setQuery( $query );
$s_result = $database->loadResult();


But I can change the extra_data with this

$hika_extra = 'a:1:{s:7:"xxxxxxx";s:6:"'.$a_code.'";}';
$query = "UPDATE #__hikaserial_serial
SET serial_extradata = '{$hika_extra}'
WHERE serial_data = '{$serial}'";
$database->setQuery( $query );
$s_result = $database->loadResult();

Any ideas why?

Conrad

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

  • Posts: 26166
  • Thank you received: 4029
  • MODERATOR
12 years 1 month ago #77774

Hi,

Yes there was a misspelled on "hikaserial::get"
I have edit/fix my code in my previous thread.

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: 98
  • Thank you received: 3
12 years 1 month ago #77781

Jerome,

the corrected version does not work. I'm using this in Chronoforms v3 On Submit code. This time around I get a blank page. Feel like I'm moving backwards not forwards.

Generally where can I find documentation on how to use HikaSerial in my registration code. What I'm trying to do is set up a registration form that checks the serial is 'assigned', if it's ok then insert some data of my own into the extra data, and set the serial status to 'used'. It would also be handy to get the date of issue of the serial as well.

Any assistance you can offer to make this work appreciated particularly since I have paid 40 eu for a licence.

Conrad

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

  • Posts: 98
  • Thank you received: 3
12 years 1 month ago #77784

This works

$query = "UPDATE #__hikaserial_serial
SET serial_extradata = '{$hika_extra}', serial_status = 'used'
WHERE serial_data = '{$serial}'";
$database->setQuery( $query );
$s_result = $database->loadResult();

for some reason when I combine the updates it works even though they don't work as separate updates.

So moving forwards again. Any chance of getting the serial issue date?

Conrad

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

  • Posts: 26166
  • Thank you received: 4029
  • MODERATOR
12 years 1 month ago #77786

Hi,

We have a developer documentation which talk more about "HikaSerial plugin development".
www.hikashop.com/en/hikashop/125-hikaserial-developer.html

If you can activate the debug mode, it could help us to understand why your page is blank.
But, I think that, if the code is working "on" another component, HikaSerial might not be loaded. So, calling "hikaserial::get" could not work properly.
At this moment, you can just add this code in order to load the HikaSerial helper.

$serial_id = 0: // Your serial id.
if(!defined('DS'))
	define('DS', DIRECTORY_SEPARATOR);
$init = defined('HIKASERIAL_COMPONENT');
if(!$init) {
	$filename = rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikaserial'.DS.'helpers'.DS.'helper.php';
	if(file_exists($filename)) {
		include_once($filename);
		$init = defined('HIKASERIAL_COMPONENT');
	}
}
if($init) {
	$serialClass = hikaserial::get('class.serial'); // Load the serial class.
	if(empty($serialClass)) {
		echo 'Failed loading the serial class';
		exit;
	}
	$serial = new stdClass();
	if((int)$serial_id > 0)
		$serial->serial_id = (int)$serial_id;
	$serial->serial_status = 'used';
	$ret = $serialClass->save($serial);
	var_dump($ret); // Should display the $serial_id value.
} else {
	echo 'Failed loading HikaSerial helper';
	exit;
}

After that, there is a documentation page which talk about "consume" feature and web services.
www.hikashop.com/en/hikashop/138-hikaserial-consume.html
You can access to his functions (check / consume) thanks to the $serialClass.

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.
Last edit: 12 years 1 month ago by Jerome.

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

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