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

#   New event suggestion

##

- **[braverman](/forum/user/30455-braverman "View braverman's Profile")**
- [![braverman's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/30455-braverman "View braverman's Profile") Topic Author
- [ Offline](/forum/user/30455-braverman)

Less More

- Posts: 25
- Thank you received: 2
-
-

5 years 3 months ago [\#334422](#334422) by [braverman](/forum/user/30455-braverman "View braverman's Profile")  *[New event suggestion](/forum/31-development/902963-new-event-suggestion#334422 "-- url of the page with the problem -- :   www.starbrite.cz/  -- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.28 -- PHP version -- : 7.4.20  Hi,  I have some suggestion - to add new event during updating of product quantity when saving order. I have some actions that has to be done on each order product save and so I made a hack now that is firing an event in method updateQuantityAndSales of class order&#95;product.php. It looks like this:  And of course I am using it in my plugin.  Does it make sense or is it completely out of sense and there is better way how to do it. If it looks meaningful for you please consider to implement it in official code.  Thanks, Jan")* was created by *[braverman](/forum/user/30455-braverman "View braverman's Profile")*

-- url of the page with the problem -- : [ www.starbrite.cz/](https://www.starbrite.cz/)
-- HikaShop version -- : 4.4.3
-- Joomla version -- : 3.9.28
-- PHP version -- : 7.4.20

Hi,

I have some suggestion - to add new event during updating of product quantity when saving order. I have some actions that has to be done on each order product save and so I made a hack now that is firing an event in method updateQuantityAndSales of class order_product.php. It looks like this:
Code:

if($localCancel) { $query = 'UPDATE '.hikashop_table('product').' SET product_quantity = product_quantity + '.(int)$k.' WHERE product_id IN ('.implode(',',$update).') AND product_quantity &gt; -1'; } else { $query = 'UPDATE '.hikashop_table('product').' SET product_quantity = GREATEST(0, product_quantity - '.(int)$k.') WHERE product_id IN ('.implode(',',$update).') AND product_quantity &gt;= 0'; } $this-&gt;database-&gt;setQuery($query); $this-&gt;database-&gt;execute(); // QN hack // 2021-07-14 JPluginHelper::importPlugin( 'hikashop' ); $app = JFactory::getApplication(); $app-&gt;triggerEvent('onAfterOrderProductSave', array($k, $update, $localCancel) ); // END QN hack

And of course I am using it in my plugin.

Does it make sense or is it completely out of sense and there is better way how to do it. If it looks meaningful for you please consider to implement it in official code.

Thanks,
Jan

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

- **[braverman](/forum/user/30455-braverman "View braverman's Profile")**
- [![braverman's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/30455-braverman "View braverman's Profile") Topic Author
- [ Offline](/forum/user/30455-braverman)

Less More

- Posts: 25
- Thank you received: 2
-
-

5 years 3 months ago [\#334423](#334423) by [braverman](/forum/user/30455-braverman "View braverman's Profile")  Replied by *[braverman](/forum/user/30455-braverman "View braverman's Profile")* on topic *[New event suggestion](/forum/31-development/902963-new-event-suggestion#334423 "-- url of the page with the problem -- :   www.starbrite.cz/  -- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.28 -- PHP version -- : 7.4.20  Hi,  I have some suggestion - to add new event during updating of product quantity when saving order. I have some actions that has to be done on each order product save and so I made a hack now that is firing an event in method updateQuantityAndSales of class order&#95;product.php. It looks like this:  And of course I am using it in my plugin.  Does it make sense or is it completely out of sense and there is better way how to do it. If it looks meaningful for you please consider to implement it in official code.  Thanks, Jan")*

Of course it would be better to take importPlugin and getApplication out of loop:)

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

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

5 years 3 months ago [\#334425](#334425) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[New event suggestion](/forum/31-development/902963-new-event-suggestion#334425 "-- url of the page with the problem -- :   www.starbrite.cz/  -- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.28 -- PHP version -- : 7.4.20  Hi,  I have some suggestion - to add new event during updating of product quantity when saving order. I have some actions that has to be done on each order product save and so I made a hack now that is firing an event in method updateQuantityAndSales of class order&#95;product.php. It looks like this:  And of course I am using it in my plugin.  Does it make sense or is it completely out of sense and there is better way how to do it. If it looks meaningful for you please consider to implement it in official code.  Thanks, Jan")*

Hi,

Thanks for your feedback.
Adding a trigger in the updateQuantityAndSales function makes sense.
Now, I can't agree with the name of the trigger event since the saving in hikashop_order_product is actually done in the save function of the same file, after the call to updateQuantityAndSales.
Also, I would prefer to add the trigger outside of the loop. In fact, I would rather add one before the loop and one after the loop, like so: Code:

JPluginHelper::importPlugin('hikashop'); $app = JFactory::getApplication(); $app-&gt;triggerEvent('onBeforeProductStockUpdate', array(&amp;$updates, $cancel)); if(!empty($updates)) { ... loop code ... $app-&gt;triggerEvent('onAfterProductStockUpdate', array(&amp;$updates, $cancel)); }

That way, plugins can even cancel the stock update by emptying the $updates array in the onBeforeProductStockUpdate event.

What do you think ? Does this still work for the custom plugin you're working on ?

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

- **[braverman](/forum/user/30455-braverman "View braverman's Profile")**
- [![braverman's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/30455-braverman "View braverman's Profile") Topic Author
- [ Offline](/forum/user/30455-braverman)

Less More

- Posts: 25
- Thank you received: 2
-
-

5 years 3 months ago [\#334474](#334474) by [braverman](/forum/user/30455-braverman "View braverman's Profile")  Replied by *[braverman](/forum/user/30455-braverman "View braverman's Profile")* on topic *[New event suggestion](/forum/31-development/902963-new-event-suggestion#334474 "-- url of the page with the problem -- :   www.starbrite.cz/  -- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.28 -- PHP version -- : 7.4.20  Hi,  I have some suggestion - to add new event during updating of product quantity when saving order. I have some actions that has to be done on each order product save and so I made a hack now that is firing an event in method updateQuantityAndSales of class order&#95;product.php. It looks like this:  And of course I am using it in my plugin.  Does it make sense or is it completely out of sense and there is better way how to do it. If it looks meaningful for you please consider to implement it in official code.  Thanks, Jan")*

Yes, that makes sense, way better than my suggestion. I can work with with no problem. Thanks!

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

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

5 years 3 months ago [\#334476](#334476) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[New event suggestion](/forum/31-development/902963-new-event-suggestion#334476 "-- url of the page with the problem -- :   www.starbrite.cz/  -- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.28 -- PHP version -- : 7.4.20  Hi,  I have some suggestion - to add new event during updating of product quantity when saving order. I have some actions that has to be done on each order product save and so I made a hack now that is firing an event in method updateQuantityAndSales of class order&#95;product.php. It looks like this:  And of course I am using it in my plugin.  Does it make sense or is it completely out of sense and there is better way how to do it. If it looks meaningful for you please consider to implement it in official code.  Thanks, Jan")*

Hi,

Great. We'll add that for the next version.

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

- **[braverman](/forum/user/30455-braverman "View braverman's Profile")**
- [![braverman's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/30455-braverman "View braverman's Profile") Topic Author
- [ Offline](/forum/user/30455-braverman)

Less More

- Posts: 25
- Thank you received: 2
-
-

5 years 3 months ago [\#334484](#334484) by [braverman](/forum/user/30455-braverman "View braverman's Profile")  Replied by *[braverman](/forum/user/30455-braverman "View braverman's Profile")* on topic *[New event suggestion](/forum/31-development/902963-new-event-suggestion#334484 "-- url of the page with the problem -- :   www.starbrite.cz/  -- HikaShop version -- : 4.4.3 -- Joomla version -- : 3.9.28 -- PHP version -- : 7.4.20  Hi,  I have some suggestion - to add new event during updating of product quantity when saving order. I have some actions that has to be done on each order product save and so I made a hack now that is firing an event in method updateQuantityAndSales of class order&#95;product.php. It looks like this:  And of course I am using it in my plugin.  Does it make sense or is it completely out of sense and there is better way how to do it. If it looks meaningful for you please consider to implement it in official code.  Thanks, Jan")*

Super, thanks!

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwMjk2My1uZXctZXZlbnQtc3VnZ2VzdGlvbj90bXBsPW1hcmtkb3du) 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?

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

Time to create page: 0.060 seconds

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