onBeforeVoteCreate object

  • Posts: 114
  • Thank you received: 14
11 years 1 week ago #131781

Hi.

I am trying to get the product id + product name within the onBeforeVoteCreate method via its $element object for a jomsocial activity stream plugin that I am writing but when I do a var dump on $object it appears to be empty.

The documentation does not give a breakdown of the $element object and a search of the forums gives me no results.

I've tried $element->product_id but still I get nothing.

All help and advice greatly appreciated.

TIA

DM/

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 1 week ago #131797

Hi,

You should have done a var_dump on $element not $object if you defined the first variable of the function as $element.
The product id is available with $element->vote_ref_id
You can then load the product name like that:
$class = hikashop_get('class.product');
$product = $class->get($element->vote_ref_id);
echo $product->product_name;

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

  • Posts: 114
  • Thank you received: 14
11 years 1 week ago #131982

Thanks Nicolas,

Quick and accurate advice as usual. :D

I incorrectly stated that I could not see the contents of $object, it was in fact $element as you suggested. My issue turned out to be that I could not see the results of the var_dump in the browser. I changed to use error_log(var_export($element, true)) and viewed the contents within the error.log instead and managed to get the full structure.

For anyone else looking for the structure of the $element object it is as follows:

stdClass::__set_state(array(
   'hikashop_vote_type' => 'comment',
   'vote_ref_id' => 2,
   'user_id' => 2,
   'pseudo_comment' => '0',
   'email_comment' => '0',
   'vote_type' => 'product',
   'vote' => 0,
   'comment' => 'hhhmmmnnn',
))

DM/

The following user(s) said Thank You: Xavier

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

Time to create page: 0.053 seconds
Powered by Kunena Forum