Avoiding duplicate serial generation

  • Posts: 51
  • Thank you received: 2
  • Hikaserial Standard Hikashop Business
5 years 11 months ago #291849

-- Browser(s) name and version -- : Chrome
-- Error-message(debug-mod must be tuned on) -- : Not an error

Hi,
I have a custom serial generator which creates serials for products.
However, and order can have the same product on multiple lines because we use custom fields.

e.g.
Line Item 1: Qty 2, Product 123, CustomField: ABC (serial gen CustomGenPack attached)
Line Item 2: Qty 1, Product 123, CustomField: DEF (serial gen CustomGenPack attached)

The desired behaviour would to generate 3 serials. 2 for line item 1, and one for line item 2

The problem is, the serial generator is run twice, once for each instance of the product, with the result that I actually generate 6 serials - 3 for each order line.

How can this be avoided? Is there any way to identify which order line is being called within the serial generator?

Many thanks,
Oliver

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

  • Posts: 25999
  • Thank you received: 4004
  • MODERATOR
5 years 11 months ago #291850

Hello,

How many serials are generated when you're using a "classical" generator like "random generator" ?

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: 51
  • Thank you received: 2
  • Hikaserial Standard Hikashop Business
5 years 11 months ago #291868

Hi Jerome,

I'm not sure I follow... why would this be of any use?
The randomgen.php code doesn't even reference the $order parameter that's passed into generate().
Instead it generates a number of serials based on the "$quantity" parameter which I've never been able to understand how this can relate to the specific order.

Is $quantity the same value as $order->cart->order_product_quantity for a specific line item? Or is it the quantity value that's specified in the licence pack of the product page? Or something else?

I'm happy to look through code examples as a form of documentation when they're relevant and easy to follow, but I'm not sure the randomgen works in this instance. If there's another example I can follow I'll happily have a go.

Many thanks,
Oliver

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

  • Posts: 25999
  • Thank you received: 4004
  • MODERATOR
5 years 11 months ago #291874

Hello,

The generate function is called for the different elements and the quantity parameter indicates what you have to generate.
So if you create more than the value, it will have an unwanted side effect.

I don't know how you are generating your serials exactly but I suspect that it creates more than it should.
That is why I'm asking you how it react with the classical generator so I can confirm the generation behavior and try to understand what should be changed in your generator to follow the normal workflow.

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: 51
  • Thank you received: 2
  • Hikaserial Standard Hikashop Business
5 years 11 months ago #291902

Hi Jerome,

Sorry - using the randomgen creates (in the case of my example) 3 serials - which is what one would expect. My issue here is that the $quantity parameter may well represent the number of keys to generate for each order line, but how does the generate method /know/ which order line is being processed?

Here's my (heavily redacted) generator function which hopefully give you a better idea of what I'm trying to accomplish.

Essentially, the custom field "customfield" is essential to the serial generation logic.

public function generate(&$pack, &$order, $quantity, &$serials) {
		if(!isset($pack->licencegen))
			return;

		parent::pluginParams($pack->licencegen);

		if(!empty($order->cart->products))
		{
			foreach($order->cart->products as $p)
			{
				if($p->product_id == $pack->main_product_id)
				{
					// Read the custom field
					if( isset( $p->customfield ))
					{
						$licKeyData = $p->customfield;
						$licKeyQty = $p->order_product_quantity;
					}
					else
						return false;
					
					// Create a set of serials for each product line/quantity			
					// THIS OBVIOUSLY ISN'T THE KEY GENERATION CODE ;)
					$serials[] = sprintf( "Key extension %d x %s<br/>", $licKeyQty, $licKeyData );
				}
			}
		}
		else
		{
			return false;
		}
		return true;
	}

Any help would be gratefully received!

Last edit: 5 years 11 months ago by ohall.

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

  • Posts: 25999
  • Thank you received: 4004
  • MODERATOR
5 years 11 months ago #291905

Hello,

You should take a look at the plugin "pointsgen" which can generate serials depending a value of the product (price in that case).
And please do not read the "order_product_quantity" ; you have the variable "quantity" which is giving you the real needed quantity.

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: 51
  • Thank you received: 2
  • Hikaserial Standard Hikashop Business
5 years 11 months ago #291929

Hi Jerome,

I've read through the pointsgen code and once all of the complexity of the serial generation is removed it appears to boil down to:

*PSEUDOCODE*
do "$quantity" times:
  create a serial (how do I refer to a SPECIFIC order line so that I can use the custom data in the serial generation code?)
  if in test mode:
    do for each $product (order line):
       if the $product matches the pack $product
         add extraData to the serialObjs object 
  add the serial to serials[]
  return either serialObjs or serials[]

I'm afraid this is all very opaque - is there not some documentation that explains precisely how the generator is supposed to work?

My main questions are the moment are:
1. When an order is confirmed, how is the serial generate method called? Is it called once for an entire order, or once for each order line that contains a product with the assigned pack generator?
2. For each invocation of generator, how is the $quantity parameter calculated?
3. For each appropriate product line, how can I extract the specific line item data - custom fields and quantity. Note: I **NEED** the order line quantity for the licence generation - not some other $quantity value (unless this is the line item quantity?)

Many thanks,
Oliver

EDIT: So... I've now investigated a bit more and I see that the $quantity field that is passed to the generator is the same as the order line quantity, multiplied by the quantity in the product pack assignment.
I can also see that the generator is called for EACH order line.

I have to be missing something... that *has* to be a way for the generator to know which order line it is being called against?!

Last edit: 5 years 11 months ago by ohall. Reason: Further investigation...

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

  • Posts: 25999
  • Thank you received: 4004
  • MODERATOR
5 years 11 months ago #291939

Hello,

For the "generate" function, see :
www.hikashop.com/support/documentation/1...er.html#fct_generate

Most of the generators do not use given data for the generation, so they do not need to read the content of the cart products.
So the process is simpler since you just need to generate the number of serials indicated by the $quantity variable.

For some generators where you need to read the product value ; processing the cart is required so you can extract the basis information for your generator.
But you should still base the generation on the $quantity variable which give you the number of serials which need to be created.

If you take a further look at the "pointsgen" you will see that the plugin is called for the different order products ; that's why there is a check made on the order product ID.

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: 51
  • Thank you received: 2
  • Hikaserial Standard Hikashop Business
5 years 11 months ago #291962

I'm sorry Jerome, but this variety of "support" is utterly pointless. If you can help, then help. If you can't, or don't want to, then just say so and we can all move on. It's like when people ask a question on StackOverflow, and other people reply with "But why would you want to do that?! Do this instead!!" While I appreciate that people sometimes ask dumb questions, the real answer to that is often "Because after more careful thought than you have given about the problem, there's a good reason for my question, so either answer the question, or if you have nothing useful to add, don't answer at all."

Instead, you have:

  • Told me to read documentation that doesn't help - the docs on the generate function you link to are abysmal. You may as well document it with "look through the various generator methods and try to work it out for yourself".
  • Failed to respond to the direct questions I've asked, such as "when is generate() called" and "how is $quantity related to each call"
  • Told me to look harder at a piece of example code... well, I did... before I posted my reply. And the code does not help in the slightest. Instead, you're referring to a chunk of "test" code that iterates through product order lines checking to see if the $pack product ID matches the order line product ID. As I've said repeatedly - in my use case - the product order lines are THE SAME product ID, but using different custom field data. Your example only works on *different* product IDs.
  • Failed to read my own example code, where I'm doing pretty much what you say about processing the cart data already
  • Continue to bang on about using $quantity when I've already shown in tests that this cannot be used unless you can identify explicitly which product line the generate() function is being called against

So - instead of pointing me at terrible documentation and examples that don't do what I need, what would be really helpful would be a quick sketch of some code that /does/ do what I need. For example: Generate a 'serial' from the concatenation of the "order number", one "custom field" and a (quantity) "index".

For an order (A1B2) with the following order lines (where Product A uses our generator) (NOTE Both order lines are the SAME product, but are unique because of the custom field):
Product: A, Qty 2, Custom Field: "ABCD"
Product: A, Qty 3, Custom Field: "EFGH"

So that it generates 5 serials:
A1B2-ABCD-1
A1B2-ABCD-2
A1B2-EFGH-1
A1B2-EFGH-2
A1B2-EFGH-3

Can you provide a bare bones example (just the generate function, no extra fluff) that would accomplish this?

I'm starting to think that the architecture of the serial generator simply doesn't allow for this. <sarcasm>You can find more information about my specific use case in this informative article en.wikipedia.org/wiki/Cats_and_the_Internet </sarcasm>

I'm sorry my reply has become so ranty, but what should have been a simple support request has turning into an experience akin to trying to get blood out of a stone.

Last edit: 5 years 11 months ago by ohall. Reason: typo

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

  • Posts: 25999
  • Thank you received: 4004
  • MODERATOR
5 years 11 months ago #291972

Hello,

Our support is there to help with the usage of our components but we do not do custom development or custom services.

You came with the description of a bug ; I asked you to confirm the bug with another generator.
Afterwards, I told you about another generator plugin which is more related to what you want to achieve.
You're asking for a "bar bones example" but I already told you to test the "points generator".

Now, I can see that you're frustrated and a bit angry.
But you're currently using an old version of HikaSerial (1.10.4) and your license expired one year ago.

Don't you think there is some kind of irony ?

Nevertheless yes, I can see to add a new "basis" plugin in the next version of HikaSerial which would use an item custom field as reference point. I'll put my ideas in the TODO list.


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: 51
  • Thank you received: 2
  • Hikaserial Standard Hikashop Business
5 years 11 months ago #292016

Hi Jerome,

You might want a bigger spade as the whole you're digging is getting bigger with each post. The irony is all yours.

First of all, I explicitly said in my first post this is not an "error" (which I think most people would take as synonymous with "bug" in this context).
Secondly, I'm not asking for you to do custom development or services - I've written the generator myself - I just want you to properly support your product by documenting its essential working and behaviour properly. That is assuming the HikaSerial product page is suggesting user custom plugins are supported? ("Use plugins to have a custom generation and custom display")
Thirdly, as I replied more than once, the randomgen and pointsgen examples don't cover my use case (so are, in this case, largely irrelevant). As I also pointed out in my previous posts, I have *carefully* examined pointsgen (I printed it out, and took a pen to all of the unnecessary code to leave what might be relevant, and concluded that it didn't help.)

Correct, I'm on an old version of HikaSerial, but if this is the quality of support one gets, why would anyone extend their support after initial purchase? Honestly, if your first post had been "I can't provide support because you're support period has expired" then this would have been a better experience.

I've sorted out my issue with what feels like a hack, but it works. If anyone happens to come across this thread with a similar issue I'd be more than happy to explain where the HikaSerial plugin is deficient and how I've handled my specific requirement.

Despite the implication that custom serial plugins are "self support" - Jerome - if I upgrade from 1.10.4 to 2.1.1 will this break anything?

Last edit: 5 years 11 months ago by ohall. Reason: grammar

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

  • Posts: 25999
  • Thank you received: 4004
  • MODERATOR
5 years 11 months ago #292035

Hello,

I've sorted out my issue with what feels like a hack, but it works. If anyone happens to come across this thread with a similar issue I'd be more than happy to explain where the HikaSerial plugin is deficient and how I've handled my specific requirement.

Despite the implication that custom serial plugins are "self support" - Jerome - if I upgrade from 1.10.4 to 2.1.1 will this break anything?

It would depends if you have modified elements in the HikaSerial core or not.
But if all is within your generator plugin ; the plugin interfaces/functions haven't change between HikaSerial 1.x and HikaSerial 2.x.

Some elements of the core has been rewrite in order to handle the "subscription" features provided by HikaSerial Subscription and the backend UI has been cleaned up.
HikaSerial 2.x have also various modification to handle high quantity of serial in websites ; we now have users with several millions of serials (and orders with hundreds of serials). We gathered information and feedback in order to perform optimizations and some are still under development.

Afterwards, when you perform an update, and specially a major one, a backup is still recommended for safety.

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.

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