- Posts: 90
- Thank you received: 1
Generate Serial based on Product and option
I know you can customize the generators to some extent, but I need to know if it is possible to generate a software key based on the product they choose and an option choice.
If this is possible, could you point in the direction on how to accomplish this? I know basic/intermediate javascript but very little PHP so any assistance will be greatly appreciated.
Please Log in or Create an account to join the conversation.
You can easily create your own generator plugin for HikaSerial.
There are several example plugins in the package, you can duplicate the, change their name and create your own algorithm.
HikaSerial have a developper documentation which would explain you the different triggers with for the most important of them, a little portion of source code (for the example).
www.hikashop.com/en/hikashop/125-hikaserial-developer.html
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.
Please Log in or Create an account to join the conversation.
I need some help.
I have my serial algorithm coded now in PHP. (Took me a few hours for some simple string replacing algorithms we use in our other software:: I'm new to PHP, but I did it!) :laugh:
I have a copy of the "Random Generator" out on our site and I need to use it as a base for implementing my new generator code.
Basically I have 2 parameters that I need to gather from the order (Software Type, Option Selected) that I need to pull into my algorithm.
I guess I don't understand the Plugin Params and Generate section of the developer documentation. Could you elaborate on how to tie in my params and generate with my php code?
Please Log in or Create an account to join the conversation.
The generate function have several parameters. In these parameters you have the $order object which contains all information of the order.
You can access to the order custom fields in the same time.
If you have a custom field named "software_type" (the name and not the label), you can access it by: $order->software_type.
If you want to read an item custom field, you have to check the order cart like it is done in the plugin "secure ebook".
If you want to example on the plugin params you can check the "secure ebook" plugin too.
You can create as many params as you want in the plugin, they would be serialized and stored in the database.
In the configuration file, you have to use a specific name for your inputs like:
In the plugin afterwards, you can access to this parameters.
First you have to call the plugin system in order to load your parameters for your plugin instance (because you can have several configurations in the same plugin).
If you plugin is not a "multiple configuration" plugin, you should load the parameters with another command:
And after you can access to the parameters like
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.
I'm a little unclear on how these return the license/serial that gets tied to the order and how it gets displayed to the end user in their email/account/order.
I may have more questions as I dive deeper.
Please Log in or Create an account to join the conversation.
The last parameter of the "generate" function is "&$serials".
It is an output array where your plugin have to put your serials.
The generate function provide serial keys (with some extra data if required) and after that, HikaSerial would insert the full serial data into the database.
When a serial is generated, HikaSerial would automatically display it to the user in the email, in his order, etc.
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.
I should also specify what I said earlier:
I really only need what the product was (where I will get software type) and the option they chose upon adding it to their cart. These two things will be all I need to run through my generating algorithm.
So really I have no parameters or configuration that needs to be set. Can I ignore that stuff or strip it out?
Please Log in or Create an account to join the conversation.
The payment plugins "collect on delivery" allow you to create easily some test orders.
So you can place a test order, confirm it manually and use the "refresh association" button.
By deleting the serial in the database, you can re-generate one by pressing the button.
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.
I've gone through the documentation and it is hard to understand. I understand there's a first language difference as well, but It's just not very thorough to start.
I don't need much complexity in my implementation. I don't have any configuration necessary. I just need it to grab the product from order object and any options that they added.
I've set up my licensegen.php with what should return a value no matter what... But I don't know if I understand the basic hikaserial setup properly. Do I need to use the PACK setup if I am generating a license one-off for each order and having them attached to the order? If not, how do I accomplish this.
I have a pack set up with my current plugin, and I have it selected in the respective product that should get a license. When I place an order and confirm it, nothing attaches, nor does anything get created.
Here's my licensegen.php (without my algorithm)
BTW: I know this doesn't contain the code for my product / options designation yet...
I'm sorry to keep bombarding you with this stuff, but this is the last step to get our store online and I feel like I'm banging my head.
Please Log in or Create an account to join the conversation.
In your plugin, you should use this code for the trigger onPackGeneratorTypeDisplay:
A serial is generated only when the order is confirmed (or depending on the HikaSerial configuration).
If nothing generated, it could have a problem during the generation. You could add some traces in your plugin in order to check that he is right called (just putting some "echo" or "var_dump" would help you).
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.
EDIT:
It appears to be generating now.
It wouldn't attach without the Link to product quantity to be set to yes. I didn't expect this as I have these products on an unlimited quantity.
Thoughts?
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
If your plugin have the "protected $populate = false;" as describe in your previous post, HikaSerial can't use the "Generate" button in the pack.
At this moment you would have a message: "This generator can't populate the database".
You don't want to have the "populate" feature because your algorithm needs the order information to generate a serial.
Did you put some traces as mentioned ?
The order object documentation could be found here: www.hikashop.com/fr/support/documentation/156
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.
I will try adding some traces, but I am not sure how to get them to show up and where they will. I have an echo in place but it doesn't seem to pop up anywhere.
Thanks for the doc, that will be helpful.
Please Log in or Create an account to join the conversation.
I need the product and one option that I need to pull from the cart order into my generator ("Concurrent Users")... what would that look like?
EDIT:
I have figured out how to pull the product code to my algorithm, but am having issues getting the option for that product.
Please Log in or Create an account to join the conversation.
If you want to be sure that your function is right called, you can put a temporally "die('a message');" in order to stop the process and see if you are entering in a function (or in a condition).
A little bit "rude" but it could help.
What are "options for products ?
In the order object, you can read the information from the table "order_product" but if you want more information about one specific product, you have to load it as explain before ( www.hikashop.com/en/forum/17-serial-how-...nd-option.html#95454 ).
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.
Can you explain this?
Please Log in or Create an account to join the conversation.
I guess the only relationship between them (from what I can tell) is the parent_id. I guess I need to figure out how to use that to grab the proper order_characteristic using that parent_id, I'm just not a PHP guru like you guys.
Please Log in or Create an account to join the conversation.
Options, variant or custom field ?
Why using options ? Are you sure that's the right solution ?
Why not using item custom field as advised ?
I do not understand your question and your structure.
Please give me real details, example, something to understand what you're talking about.
You're talking about "options" but giving names of "variants" organization. So, I don't know what you are really using and having in your website.
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.