Notification if someone change quantity

  • Posts: 1027
  • Thank you received: 11
  • Hikashop Business
1 year 1 month ago #350213

Hello!
Is there a way to restrict the quantity edit on certain usergroups?
Or notify via email the admin if somenone saves a product with changed number in the field quantity?

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 1 month ago #350217

Hi,

While there is no ready-made solution, there are two things I can propose:
- This plugin integrates with Joomla's logging system:
www.hikashop.com/marketplace/product/161-action-log.html
With it, you can log who modified the products when.
- You could create a mass action with a trigger "before a product is updated" and an action "run PHP code".
In the action, you can write a bit of PHP to:
1. check if the quantity is being changed
2. check the user group of the current user
3. stop the process with an error message
For example, something like that (not tested):

$new_qty = (int)'{product_quantity}';
$db = JFactory::getDBO();
$db->setQuery('SELECT product_quantity FROM #__hikashop_product WHERE product_id = {product_id}');
$old_qty = $db->loadResult();
if($new_qty != $old_qty) {
 if(!hikashop_isAllowed('XXX,YYY')) {
  die('you are not allowed to change the quantity');
 }
}
where XXX and YYY are the user groups allowed to change the quantity. You might also want to add a check on whether you're on the backend or not, as some processes on the frontend might change the quantity while you might not want to trigger your mass action at that time.

The following user(s) said Thank You: verzevoul

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

  • Posts: 1027
  • Thank you received: 11
  • Hikashop Business
1 year 3 weeks ago #350408

Hello!
Can we add on the script you send me 2 more checks?
Prevent unpublish of products and delete?

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 3 weeks ago #350414

Hi,

This would require new mass actions to be created with different code.
For the unpublish, it's quite easy. You would basically just change "product_quantity" to "product_published" in the code.

For the delete, you would just have the "before a product is deleted" trigger, and the code would simplify to just:

if(!hikashop_isAllowed('XXX,YYY')) {
  die('you are not allowed to change the quantity');
 }

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

Time to create page: 0.059 seconds
Powered by Kunena Forum