Skip to main content

quantity parameter in function generate()

More
11 years 11 months ago #175176 by ruslan_zasukhin
Hi,

On this page of docs www.hikashop.com/support/documentation/1...erial-developer.html
we have
Code:
/** * @param object $pack : the hikashop pack object, with the options. * [ pack_id, product_id, quantity, pack_name, pack_data, pack_generator, pack_params ] * @param object $order : the hikashop order object, with all data. * @param int $quantity : the quantity of serials that you generator has to create. * @param array $serials : output array for the generated serials. */ public function generate(&$pack, &$order, $quantity, &$serials) { if(!isset($pack->mypluginname)) // replace "mypluginname" by your plugin name return; // load $this->plugin_params; parent::pluginParams($pack->mypluginname); // replace "mypluginname" by your plugin name for($q = 0; $q < $quantity; $q++) { $serial = ''; /* * Generate your serial here */ $serials[] = $serial; } }


I think it is not clear how this function will be called, and what exactly $quantity is?
Let we have in CART few products with quantity

product1 1
product2 3
product3 1

How many times will be called function generate() ?
a) once? And we need self iterate each product in the array products ?
b) 3 times? once per each product?
c) 5 times?

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

More
11 years 11 months ago #175179 by Jerome
Hi,
Code:
@param int $quantity : the quantity of serials that you generator has to create.
If you have different products, the function will be called for each product.

You have to product information in the variable : $pack
Code:
[ pack_id, product_id, quantity, pack_name, pack_data, pack_generator, pack_params ]
The "product_id" is the id of the product that your current "generate" call will create the serial

That's why you can find that code in the plugin "secure e-book" (that I am once again recommend you as sample).
Code:
$product_code = ''; if(!empty($order->cart->products)) { foreach($order->cart->products as $p) { if($p->product_id == $pack->product_id) { $product_code = $p->order_product_code; break; } } }
Which allow the plugin to load an element from the product (here the product code) for the serial it has to generate.

Regards,

Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
The following user(s) said Thank You: ruslan_zasukhin

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

More
11 years 11 months ago #175187 by ruslan_zasukhin
Code:
if($p->product_id == $pack->product_id) {

Aha! Now I see what this line do :)

yes I did see this plugin, but believe me, without such explain and KEY WORDS, that function it is called once per product ... it is near to impossible guess something :)

Thank you very much for answer

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

More
11 years 11 months ago #175188 by Jerome
Hi,

I will see to let the commentaries in the HikaSerial plugins ; our packager remove all in order to reduce the size of the packages.

Regards,

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

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

More
11 years 11 months ago - 11 years 11 months ago #177728 by ruslan_zasukhin
Hi Jerome,

by the way, I think this line should looks as

if( $p->product_id == $pack->main_product_id )
instead of
if($p->product_id == $pack->product_id) {

Because we have products with variants, and the correct ID of product variant is in the $pack->main_product_id

May be in secure_book this is onto important ...
Last edit: 11 years 11 months ago by ruslan_zasukhin.

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

More
11 years 11 months ago #177741 by Jerome
Hi,

Thanks for the report ; I will perform some tests.
Like that I think that maybe two "foreach" are needed, because you can associate the pack to the main product or to the variant ; but I'll test it, it will be easier !

Regards,

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

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

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