onBeforeVoteCreate object
12 years 10 months ago #131781
by DeeEmm
onBeforeVoteCreate object was created by DeeEmm
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/
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.
12 years 10 months ago #131797
by nicolas
Replied by nicolas on topic onBeforeVoteCreate object
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;
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.
12 years 10 months ago #131982
by DeeEmm
Replied by DeeEmm on topic onBeforeVoteCreate object
Thanks Nicolas,
Quick and accurate advice as usual.
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:
DM/
Quick and accurate advice as usual.

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:
Code:
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.177 seconds