[Skip to main content](#vessel-content)

#   quantity parameter in function generate()

##

- **[ruslan\_zasukhin](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile")**
- [![ruslan&#95;zasukhin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar34181.jpg)](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile") Topic Author
- [ Offline](/forum/user/34181-ruslan-zasukhin)

Less More

- Posts: 37
- Thank you received: 1
-
-

12 years 1 month ago [\#175176](#175176) by [ruslan\_zasukhin](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile")  *[quantity parameter in function generate()](/forum/15-general-talk-about-hikaserial/872245-quantity-parameter-in-function-generate#175176 "Hi,  On this page of docs   www.hikashop.com/support/documentation/1...erial-developer.html  we have  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?")* was created by *[ruslan\_zasukhin](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile")*

Hi,

On this page of docs [ www.hikashop.com/support/documentation/1...erial-developer.html](http://www.hikashop.com/support/documentation/125-hikaserial-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(&amp;$pack, &amp;$order, $quantity, &amp;$serials) { if(!isset($pack-&gt;mypluginname)) // replace "mypluginname" by your plugin name return; // load $this-&gt;plugin_params; parent::pluginParams($pack-&gt;mypluginname); // replace "mypluginname" by your plugin name for($q = 0; $q &lt; $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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE1LWdlbmVyYWwtdGFsay1hYm91dC1oaWthc2VyaWFsLzg3MjI0NS1xdWFudGl0eS1wYXJhbWV0ZXItaW4tZnVuY3Rpb24tZ2VuZXJhdGU/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Away](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26401
- Thank you received: 4081
-
- [](http://obsi.dev)
-

12 years 1 month ago [\#175179](#175179) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[quantity parameter in function generate()](/forum/15-general-talk-about-hikaserial/872245-quantity-parameter-in-function-generate#175179 "Hi,  On this page of docs   www.hikashop.com/support/documentation/1...erial-developer.html  we have  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?")*

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-&gt;cart-&gt;products)) { foreach($order-&gt;cart-&gt;products as $p) { if($p-&gt;product_id == $pack-&gt;product_id) { $product_code = $p-&gt;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 &amp; HikaSerial developer / HikaShop core dev team.

The following user(s) said Thank You: [ruslan\_zasukhin](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE1LWdlbmVyYWwtdGFsay1hYm91dC1oaWthc2VyaWFsLzg3MjI0NS1xdWFudGl0eS1wYXJhbWV0ZXItaW4tZnVuY3Rpb24tZ2VuZXJhdGU/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[ruslan\_zasukhin](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile")**
- [![ruslan&#95;zasukhin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar34181.jpg)](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile") Topic Author
- [ Offline](/forum/user/34181-ruslan-zasukhin)

Less More

- Posts: 37
- Thank you received: 1
-
-

12 years 1 month ago [\#175187](#175187) by [ruslan\_zasukhin](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile")  Replied by *[ruslan\_zasukhin](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile")* on topic *[quantity parameter in function generate()](/forum/15-general-talk-about-hikaserial/872245-quantity-parameter-in-function-generate#175187 "Hi,  On this page of docs   www.hikashop.com/support/documentation/1...erial-developer.html  we have  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?")*

Code:

if($p-&gt;product_id == $pack-&gt;product_id) {

Aha! Now I see what this line do ![:)](/media/kunena/emoticons/3.png ":)")

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 ![:)](/media/kunena/emoticons/3.png ":)")

Thank you very much for answer

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE1LWdlbmVyYWwtdGFsay1hYm91dC1oaWthc2VyaWFsLzg3MjI0NS1xdWFudGl0eS1wYXJhbWV0ZXItaW4tZnVuY3Rpb24tZ2VuZXJhdGU/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Away](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26401
- Thank you received: 4081
-
- [](http://obsi.dev)
-

12 years 1 month ago [\#175188](#175188) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[quantity parameter in function generate()](/forum/15-general-talk-about-hikaserial/872245-quantity-parameter-in-function-generate#175188 "Hi,  On this page of docs   www.hikashop.com/support/documentation/1...erial-developer.html  we have  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?")*

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 &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE1LWdlbmVyYWwtdGFsay1hYm91dC1oaWthc2VyaWFsLzg3MjI0NS1xdWFudGl0eS1wYXJhbWV0ZXItaW4tZnVuY3Rpb24tZ2VuZXJhdGU/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[ruslan\_zasukhin](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile")**
- [![ruslan&#95;zasukhin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar34181.jpg)](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile") Topic Author
- [ Offline](/forum/user/34181-ruslan-zasukhin)

Less More

- Posts: 37
- Thank you received: 1
-
-

12 years 3 weeks ago -  12 years 3 weeks ago [\#177728](#177728) by [ruslan\_zasukhin](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile")  Replied by *[ruslan\_zasukhin](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile")* on topic *[quantity parameter in function generate()](/forum/15-general-talk-about-hikaserial/872245-quantity-parameter-in-function-generate#177728 "Hi,  On this page of docs   www.hikashop.com/support/documentation/1...erial-developer.html  we have  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?")*

Hi Jerome,

by the way, I think this line should looks as

if( $p-&gt;product_id == $pack-&gt;main_product_id )
instead of
if($p-&gt;product_id == $pack-&gt;product_id) {

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

May be in secure_book this is onto important ...

Last edit: 12 years 3 weeks ago by [ruslan\_zasukhin](/forum/user/34181-ruslan-zasukhin "View ruslan&#95;zasukhin's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE1LWdlbmVyYWwtdGFsay1hYm91dC1oaWthc2VyaWFsLzg3MjI0NS1xdWFudGl0eS1wYXJhbWV0ZXItaW4tZnVuY3Rpb24tZ2VuZXJhdGU/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Away](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26401
- Thank you received: 4081
-
- [](http://obsi.dev)
-

12 years 3 weeks ago [\#177741](#177741) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[quantity parameter in function generate()](/forum/15-general-talk-about-hikaserial/872245-quantity-parameter-in-function-generate#177741 "Hi,  On this page of docs   www.hikashop.com/support/documentation/1...erial-developer.html  we have  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?")*

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 &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE1LWdlbmVyYWwtdGFsay1hYm91dC1oaWthc2VyaWFsLzg3MjI0NS1xdWFudGl0eS1wYXJhbWV0ZXItaW4tZnVuY3Rpb24tZ2VuZXJhdGU/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

Moderators: [Obsidev](/forum/user/7040-obsidev "View Obsidev's Profile")

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.081 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
