onAfterProductUpdate save method

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #127729

I'm writing a plugin to do some processing tasks on uploaded products. One of the things that I am trying to achieve is to modify the values of custom fields using the onAfterProductUpdate trigger.

I have successfully carried this out with the onBeforeProductcreate trigger but cannot figure out what the correct method is for onAfterProductUpdate

Here is the code I am testing

public function onAfterProductUpdate(&$product) {
	$product->my_field = 'test';			

	//I need to add correct $this->save($product) method here

}

Obviously I need to add the correctly formatted save method but I cannot find / figure out what it should be.

Any help greatly appreciated.

TIA

/DM

Last edit: 10 years 6 months ago by DeeEmm. Reason: clarity

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

  • Posts: 26007
  • Thank you received: 4004
  • MODERATOR
10 years 6 months ago #127730

Hi,

Why not using onBeforeProductUpdate ?

Quite better and not possibility of looping (it not good to save the product in the onAfterProductUpdate, you will call yourself and create an infinity trigger loop)?

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #127779

Hi Jerome, thanks for the prompt reply.

Ahh yes, of course I can see how I might end up in a loop. :-S

I am not sure if I can use onBeforeProductUpdate as ultimately I need to process some information from an uploaded file and if I understand correctly the file will not have been uploaded at this point.

I will outline what I am trying to achieve. Perhaps you could advise the best way for me to do it.

Outline...
- I am using HikaMarket to allow users to sell downloadable files.
- All files (products) are exactly the same type.
- Products have several custom fields. These are not visible to the front end vendor when they create a new product but are displayed in the product listing
- The Custom field data is extracted from source of uploaded file.

So my basic idea is something like this...
- User uploads a product for download.
- Plugin detects onAfterProductUpdate trigger and gets product id from $product -> product_id
- Plugin cross references the database #__hikashop_file table to get the filename
- Plugin passes filename to method to extract data for custom fields
- Plugin updates the custom fields.

I guess ultimately I could update the database direct but It would be good to use a built in method to do this and keep things tidy.

If you have any ideas it would be very much appreciated.

Regards

/DM

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

  • Posts: 26007
  • Thank you received: 4004
  • MODERATOR
10 years 6 months ago #127821

Hi,

In HikaMarket, the product upload is made asynchronously, even if the product does not exists.
So when you submit a new product with a file attached, this file is already in your server and already have a specific "file_id" (but no product_id).

So in the onBeforeProductUpdate, you will have the files.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: DeeEmm

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

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #127837

Thanks Jerome,

I had just implemented JFactory DB methods to update the data but being able to use onBeforeProductUpdate now makes the whole thing very much easier.

/DM

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

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #128085

Just a quick update on this.

As I opted to not display the custom fields in the front end form, what I found was that when the product was updated all of the custom fields were overwritten with NULL / Blank values. Basically the data in the custom fields was deleted.

To get over this I opted to show the fields in the front end form but to hide them with the CSS display:none attribute. This was pretty easy as each custom field has its own CSS class. I just added the relevant definitions to my templates CSS file.

Hope this helps someone out in the future.

/DM

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

  • Posts: 26007
  • Thank you received: 4004
  • MODERATOR
10 years 6 months ago #128119

Hi,

You shouldn't happen.
Which version of HikaShop/HikaMarket are you using ?

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #128156

Hi Jerome. I am using HS 2.2.1 and HM 1.3.0.

/DM

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

  • Posts: 26007
  • Thank you received: 4004
  • MODERATOR
10 years 6 months ago #128338

Hi,

Would it be possible to update to HikaShop 2.2.2 ?
I think that the problem is linked with the mass-action system because it is clearly not logical that the data are present (and null).
If the custom field is not available in the front-end, the data shouldn't be present in the object used for the save.

Can you send me a screenshot of your custom field configuration (the one which give you the problem).
I want to be sure that I have the same configuration on my side and the problem is right solve using the latest versions.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #128340

Hi Jerome, I will look at upgrading.

I actually wasn't aware that there was a more current version. Guess I should pay more attention :D

The settings are below, the only difference is that now I have the setting Display-> Front End set to yes instead of no.

Attachments:

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

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #128341

Jerome,

A bit off topic but just to let you know. My installation is showing as up to date even though version 2.2.1 is installed.

The Admin dashboard says 'All extensions are up-to-date'
The Hikashop > documentation > update / about says 'You have the latest stable version of HikaShop Business: 2.2.1'

I am using Joomla! 3.1.5

Seems to be an issue with the auto updater

/DM

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

  • Posts: 26007
  • Thank you received: 4004
  • MODERATOR
10 years 6 months ago #128451

Hi,

There is no issue for the auto updater, the 2.2.2 release is not pushed in auto-update.
It is explained in the change log:
www.hikashop.com/support/documentation/5...ashop-changelog.html

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #128469

See, told you I should pay more attention :lol: :lol: :lol: :lol:

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

Moderators: Obsidev
Time to create page: 0.085 seconds
Powered by Kunena Forum