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

#   onBeforeProductupdate() Trigger firing

##

- **[brainforge](/forum/user/423-brainforge "View brainforge's Profile")**
- [![brainforge's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar423.jpg)](/forum/user/423-brainforge "View brainforge's Profile") Topic Author
- [ Offline](/forum/user/423-brainforge)

Less More

- Posts: 298
- Thank you received: 5
-
-
-
- [](https://brainforge.co.uk)
-

15 years 5 months ago [\#18324](#18324) by [brainforge](/forum/user/423-brainforge "View brainforge's Profile")  *[onBeforeProductupdate() Trigger firing](/forum/3-bug-report/18324-onbeforeproductupdate-trigger-firing#18324 "Thanks for the new triggers.  Works fine when invoked from the product maintenance form.  However, when the published icon is clicked in the product listing this trigger does not get called. Could this be added please as I want to know when a product as been published.  Presumably also applies to category triggers, but I have not tried.")* was created by *[brainforge](/forum/user/423-brainforge "View brainforge's Profile")*

Thanks for the new triggers.

Works fine when invoked from the product maintenance form.

However, when the published icon is clicked in the product listing this trigger does not get called.
Could this be added please as I want to know when a product as been published.

Presumably also applies to category triggers, but I have not tried.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMtYnVnLXJlcG9ydC8xODMyNC1vbmJlZm9yZXByb2R1Y3R1cGRhdGUtdHJpZ2dlci1maXJpbmc/dG1wbD1tYXJrZG93bg==) 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")
- [ Away](/forum/user/63-nicolas)

Less More

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

15 years 5 months ago [\#18339](#18339) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: onBeforeProductupdate() Trigger firing](/forum/3-bug-report/18324-onbeforeproductupdate-trigger-firing#18339 "Thanks for the new triggers.  Works fine when invoked from the product maintenance form.  However, when the published icon is clicked in the product listing this trigger does not get called. Could this be added please as I want to know when a product as been published.  Presumably also applies to category triggers, but I have not tried.")*

Indeed, the triggers are not called for the toggles on the listings of the backend.

Please edit the file administrator/components/com_hikashop/controllers/toggle.php and change the lines:
if(method_exists($class,'getTable')){
$table = $class-&gt;getTable();
}else{
$table = hikashop::table($controllerName);
}
$db =&amp; JFactory::getDBO();
$db-&gt;setQuery('UPDATE '.$table.' SET '.$task.' = '.$db-&gt;Quote($value).' WHERE '.$class-&gt;toggle[$task].' = '.$db-&gt;Quote($elementPkey).' LIMIT 1');
$db-&gt;query();

to:
$obj = null;
$obj-&gt;$task = $value;
$id = $class-&gt;toggle[$task];
$obj-&gt;$id = $elementPkey;
$class-&gt;save($obj);

That should trigger the events for everything. Let us know how that goes as we would include that in next release if it works properly. On our end, it seems that everything is still working ![:)](/media/kunena/emoticons/3.png ":)")

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

- **[brainforge](/forum/user/423-brainforge "View brainforge's Profile")**
- [![brainforge's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar423.jpg)](/forum/user/423-brainforge "View brainforge's Profile") Topic Author
- [ Offline](/forum/user/423-brainforge)

Less More

- Posts: 298
- Thank you received: 5
-
-
-
- [](https://brainforge.co.uk)
-

15 years 5 months ago [\#18344](#18344) by [brainforge](/forum/user/423-brainforge "View brainforge's Profile")  Replied by *[brainforge](/forum/user/423-brainforge "View brainforge's Profile")* on topic *[Re: onBeforeProductupdate() Trigger firing](/forum/3-bug-report/18324-onbeforeproductupdate-trigger-firing#18344 "Thanks for the new triggers.  Works fine when invoked from the product maintenance form.  However, when the published icon is clicked in the product listing this trigger does not get called. Could this be added please as I want to know when a product as been published.  Presumably also applies to category triggers, but I have not tried.")*

That works, thanks.

One issue is that if the user tries to publish the product and the before update trigger sets it back to unpublished the button shows as green and not red. Have to refresh to page to make it red.

Bit confusing that, and maybe more difficult to fix.
At least its fail safe, so can be put into next release asis please.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMtYnVnLXJlcG9ydC8xODMyNC1vbmJlZm9yZXByb2R1Y3R1cGRhdGUtdHJpZ2dlci1maXJpbmc/dG1wbD1tYXJrZG93bg==) 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")
- [ Away](/forum/user/63-nicolas)

Less More

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

15 years 5 months ago [\#18345](#18345) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: onBeforeProductupdate() Trigger firing](/forum/3-bug-report/18324-onbeforeproductupdate-trigger-firing#18345 "Thanks for the new triggers.  Works fine when invoked from the product maintenance form.  However, when the published icon is clicked in the product listing this trigger does not get called. Could this be added please as I want to know when a product as been published.  Presumably also applies to category triggers, but I have not tried.")*

Indeed. To handle that case, I think we could change the line:
$class-&gt;save($obj);

to:
if(!$class-&gt;save($obj)){
if(method_exists($class,'getTable')){
$table = $class-&gt;getTable();
}else{
$table = hikashop::table($controllerName);
}
$db =&amp; JFactory::getDBO();
$db-&gt;setQuery('SELECT '.$task.' FROM '.$table.' WHERE '.$class-&gt;toggle[$task].' = '.$db-&gt;Quote($elementPkey).' LIMIT 1');
$value = $db-&gt;loadResult();
}

That way, the old value of the toggle would be reloaded if the save was not successful.

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

- **[brainforge](/forum/user/423-brainforge "View brainforge's Profile")**
- [![brainforge's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar423.jpg)](/forum/user/423-brainforge "View brainforge's Profile") Topic Author
- [ Offline](/forum/user/423-brainforge)

Less More

- Posts: 298
- Thank you received: 5
-
-
-
- [](https://brainforge.co.uk)
-

15 years 5 months ago [\#18357](#18357) by [brainforge](/forum/user/423-brainforge "View brainforge's Profile")  Replied by *[brainforge](/forum/user/423-brainforge "View brainforge's Profile")* on topic *[Re: onBeforeProductupdate() Trigger firing](/forum/3-bug-report/18324-onbeforeproductupdate-trigger-firing#18357 "Thanks for the new triggers.  Works fine when invoked from the product maintenance form.  However, when the published icon is clicked in the product listing this trigger does not get called. Could this be added please as I want to know when a product as been published.  Presumably also applies to category triggers, but I have not tried.")*

That's almost working.

(a) I needed to set the value of *DO* to false, but only on the toggle. My code now looks like this: Code:

function onBeforeProductupdate(&amp;$product, &amp;$do) { if (!myProductHelper::productValidation($product)) { $product-&gt;product_published = 0; if (JRequest::getVar('ctrl') == 'toggle') { $do = false; } } }

(b) The next problem is that the toggle only provides a partial set of *product* data in the object not the full set provided when the product form is saved. Can the call to *save* be changed to something like this? Code:

$obj = new hikashopProductClass; // Need to cater for the other classes as well. $obj-&gt;getProducts($elementPkey); $obj-&gt;$task = $value; $class-&gt;save($obj);

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMtYnVnLXJlcG9ydC8xODMyNC1vbmJlZm9yZXByb2R1Y3R1cGRhdGUtdHJpZ2dlci1maXJpbmc/dG1wbD1tYXJrZG93bg==) 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")
- [ Away](/forum/user/63-nicolas)

Less More

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

15 years 5 months ago [\#18358](#18358) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: onBeforeProductupdate() Trigger firing](/forum/3-bug-report/18324-onbeforeproductupdate-trigger-firing#18358 "Thanks for the new triggers.  Works fine when invoked from the product maintenance form.  However, when the published icon is clicked in the product listing this trigger does not get called. Could this be added please as I want to know when a product as been published.  Presumably also applies to category triggers, but I have not tried.")*

a/ Setting the do to false and the product_published to 0 is not the same. When you set the do to false, it means that the change is ignored so even if you put published to 0, that won't change in the database.

b/ In the Update events you can suppose that the data will be there every time. You should load it yourself in the plugin should you need it.

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

- **[brainforge](/forum/user/423-brainforge "View brainforge's Profile")**
- [![brainforge's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar423.jpg)](/forum/user/423-brainforge "View brainforge's Profile") Topic Author
- [ Offline](/forum/user/423-brainforge)

Less More

- Posts: 298
- Thank you received: 5
-
-
-
- [](https://brainforge.co.uk)
-

15 years 5 months ago [\#18361](#18361) by [brainforge](/forum/user/423-brainforge "View brainforge's Profile")  Replied by *[brainforge](/forum/user/423-brainforge "View brainforge's Profile")* on topic *[Re: onBeforeProductupdate() Trigger firing](/forum/3-bug-report/18324-onbeforeproductupdate-trigger-firing#18361 "Thanks for the new triggers.  Works fine when invoked from the product maintenance form.  However, when the published icon is clicked in the product listing this trigger does not get called. Could this be added please as I want to know when a product as been published.  Presumably also applies to category triggers, but I have not tried.")*

Thanks.

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

- **[brainforge](/forum/user/423-brainforge "View brainforge's Profile")**
- [![brainforge's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar423.jpg)](/forum/user/423-brainforge "View brainforge's Profile") Topic Author
- [ Offline](/forum/user/423-brainforge)

Less More

- Posts: 298
- Thank you received: 5
-
-
-
- [](https://brainforge.co.uk)
-

15 years 5 months ago [\#18366](#18366) by [brainforge](/forum/user/423-brainforge "View brainforge's Profile")  Replied by *[brainforge](/forum/user/423-brainforge "View brainforge's Profile")* on topic *[Re: onBeforeProductupdate() Trigger firing](/forum/3-bug-report/18324-onbeforeproductupdate-trigger-firing#18366 "Thanks for the new triggers.  Works fine when invoked from the product maintenance form.  However, when the published icon is clicked in the product listing this trigger does not get called. Could this be added please as I want to know when a product as been published.  Presumably also applies to category triggers, but I have not tried.")*

If anyone else find this helpful, this is the code I currently have which works both in the product form and when toggling the published state in the product listing: Code:

function onBeforeProductupdate(&amp;$product, &amp;$do) { if (!myProductHelper::productValidation($product)) { $product-&gt;product_published = 0; if (JRequest::getVar('ctrl') == 'toggle') $do = false; else $product-&gt;product_published = 0; } }

and Code:

class myProductHelper { static function productValidation($product) { /* DO NOT USE &amp;$product !! or at least make sure you don't overwrite it */ $result = true; if (... property missing ...) { $product-&gt;... = the missing property from database; } .... return $result; } }

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

- **[brainforge](/forum/user/423-brainforge "View brainforge's Profile")**
- [![brainforge's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar423.jpg)](/forum/user/423-brainforge "View brainforge's Profile") Topic Author
- [ Offline](/forum/user/423-brainforge)

Less More

- Posts: 298
- Thank you received: 5
-
-
-
- [](https://brainforge.co.uk)
-

15 years 4 months ago [\#21016](#21016) by [brainforge](/forum/user/423-brainforge "View brainforge's Profile")  Replied by *[brainforge](/forum/user/423-brainforge "View brainforge's Profile")* on topic *[Re: onBeforeProductupdate() Trigger firing](/forum/3-bug-report/18324-onbeforeproductupdate-trigger-firing#21016 "Thanks for the new triggers.  Works fine when invoked from the product maintenance form.  However, when the published icon is clicked in the product listing this trigger does not get called. Could this be added please as I want to know when a product as been published.  Presumably also applies to category triggers, but I have not tried.")*

In v1.5.2 noticed that the onBeforeProductupdate() and onAfterProductupdate() appear not to be firing if user ticks one of the selection boxes in the product admin listing screen and then clicks the (un)publish button.

Reading above posts looks like that got overlooked before.
Could this feature be added please.

Is this functionality also included with the category triggers? - I am not using them but would expect them to be consistent with the product triggers.

Thanks.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMtYnVnLXJlcG9ydC8xODMyNC1vbmJlZm9yZXByb2R1Y3R1cGRhdGUtdHJpZ2dlci1maXJpbmc/dG1wbD1tYXJrZG93bg==) 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")
- [ Away](/forum/user/63-nicolas)

Less More

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

15 years 4 months ago [\#21027](#21027) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: onBeforeProductupdate() Trigger firing](/forum/3-bug-report/18324-onbeforeproductupdate-trigger-firing#21027 "Thanks for the new triggers.  Works fine when invoked from the product maintenance form.  However, when the published icon is clicked in the product listing this trigger does not get called. Could this be added please as I want to know when a product as been published.  Presumably also applies to category triggers, but I have not tried.")*

That's another problem indeed.
It's indeed a problem for both the products and the categories.

We'll modify that for next release as the solution is bigger to implement than just changing two lines.

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

- **[brainforge](/forum/user/423-brainforge "View brainforge's Profile")**
- [![brainforge's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar423.jpg)](/forum/user/423-brainforge "View brainforge's Profile") Topic Author
- [ Offline](/forum/user/423-brainforge)

Less More

- Posts: 298
- Thank you received: 5
-
-
-
- [](https://brainforge.co.uk)
-

15 years 4 months ago [\#21030](#21030) by [brainforge](/forum/user/423-brainforge "View brainforge's Profile")  Replied by *[brainforge](/forum/user/423-brainforge "View brainforge's Profile")* on topic *[Re: onBeforeProductupdate() Trigger firing](/forum/3-bug-report/18324-onbeforeproductupdate-trigger-firing#21030 "Thanks for the new triggers.  Works fine when invoked from the product maintenance form.  However, when the published icon is clicked in the product listing this trigger does not get called. Could this be added please as I want to know when a product as been published.  Presumably also applies to category triggers, but I have not tried.")*

Thanks.

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

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

Time to create page: 0.077 seconds

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