Product "modified by" with custom field and mass action

  • Posts: 2143
  • Thank you received: 747
4 years 5 months ago #313123

-- HikaShop version -- : 4.1.0
-- Joomla version -- : 3.9.8
-- PHP version -- : 7.2.24

Hi,

I need to record which (admin) user last modified (or created) a product.
Good, so I created a custom product field with column name "product_modified_by". Pity is that in the settings of the custom field the display in the backend form can't be disabled, but no problem, I deleted the field again and. hooray, the column is still in the #__hikashop_product table. Changed it to INT(11) because I want to store the user ID there.

Off to creating a mass action...
Data: Product
Triggers: After a product is updated
Filters: none selected
Limitations: left at default (0/500)
Actions: Update the values... product_modified_by
I reckon INT won't work as I doubt a non-INT value or placeholder or so could be used. So I tried operations and various references, such as user.user_id, users.id, u.id etc etc, but when saving a product I always get "Table xyz doesn't exist".

1. How can I get the ID of the current (admin) user having created/edited the product and use it in the product-related mass action?

2. Triggers: obviously I'll need this to work on after a product is both created or updated. If I add both triggers in the same mass action, I see "And". Is that indeed the logical AND (as in both must be true, which in this case is not going to work and I'll need two mass actions, one for each trigger), or can I interpret it as OR, means I can use both in one and the same mass action? "Trial & error" would show me, of course, but your briefest answer here will be much appreciated, perhaps by others as well.

3. Just thinking... I can't imagine me being the only one needing this or, at least, finding it very helpful. Wouldn't it be nice if the column and function were there by default? Probably no further to-do required at this point... I bet that anyone who'll need it will figure it out, also how to access and make use of the data.

Thanks in advance!


Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )

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

  • Posts: 81484
  • Thank you received: 13062
  • MODERATOR
4 years 5 months ago #313124

Hi,

1. Only the tables you see when you use an "export" or "display the results" action can be used in an "update the values" action.
So the current user id is not available in that action.
So if you want to do that, it would require some development.

2. Triggers use the "OR" logic. Using "AND" wouldn't make any sense since you can't be triggered by two different triggers at the same time, so it wouldn't be logical to allow you to have several triggers. So yes, one mass action would be enough.

3. While doing something like that could be interesting for others. I would actually think of doing it differently by developing a plugin to integrate with the action logging system of Joomla. That way, you could log who does what when, but not only for products, but for any other type of data (orders, configuration saving, etc). In fact, developing such action logging plugin is on our todo list.

4. Actually, even for your case, since there is no option to do that with a mass action, I would recommend to develop a hikashop plugin where you would implement the onBeforeProductUpdate and onBeforeProductCreate triggers and update your column. It's really easy to do as it's just one line in each trigger:
$product->product_modified_by = hikashop_loadUser(false);
Since you're in the "before" trigger, the saving will be handled automatically by HikaShop.

The following user(s) said Thank You: lousyfool

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

  • Posts: 2143
  • Thank you received: 747
4 years 5 months ago #313173

Hi Nicolas,

Thank you for your response.

1. Understood, and sort of "as expected".

2. Makes sense, and good to know.

3. + 4. The idea is to have a "Last modified" column in the backend order listing displaying both date/time and user, able to be ordered by date. I already have it for date/time since the column exists.
I believe information should be given when and where it's needed, not on some other page, where it's eventually buried among a lot of other data and must first be filtered out and or searched in an extra step. So, as nice as Joomla's action logging is for other purposes, for this one it might be not so helpful. You're doing well with showing an "action log" for orders in the backend order details page - imagine that data were listed elsewhere.
I shall give it a go with a plugin. Maybe then take it further, like giving it config options such as "show in order listing", making it installable incl field/column generation etc = easily usable for others as well. Oh, if so, would I be able to put it on your marketplace?

Thanks again!


Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )

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

  • Posts: 81484
  • Thank you received: 13062
  • MODERATOR
4 years 5 months ago #313195

Hi,

We do welcome third party plugins on the marketplace. There are some requirements that we can talk about via our contact form if you want (like the code must be GPL...).

The following user(s) said Thank You: lousyfool

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

Time to create page: 0.060 seconds
Powered by Kunena Forum