eZ Community » Forums » eZ Publish 5 Platform » [EZ 5.3] - Get value of an attribute...

[EZ 5.3] - Get value of an attribute price

[EZ 5.3] - Get value of an attribute price

Tuesday 03 June 2014 2:18:46 pm - 22 replies


Is there a way to get the value of a price attribute in PHP ?

For example, I want to retrieve price value of an object (the attribute name is "price"blunk.gif Emoticon :

 $node->getFieldValue( 'price' )

This function returns NULL. However, the function works fine with other attributes. If I go in the API FieldType Classes, I can see there isn't class "Value.php" for Price field type. Is it normal ?

The question is the same in a twig template.


Monday 19 January 2015 12:39:40 pm

If I put a dump in the fromPersistenceValue méthod in the file "src/Crevillo/EzPricesBundle/eZ/Publish/Core/FieldType/Price/Type.php" like this :

 public function fromPersistenceValue( FieldValue $fieldValue )    
if( !is_null( $fieldValue->externalData ) ){      
return new Value( $fieldValue->externalData );}    

I have got always the same value... But if I clear cache, it displays a different value...

Friday 23 January 2015 9:27:14 am


We have found the solution. It is a very special case for us because the user can change its billing address in real time. So we have to change its preferred country (the "user_preferred_country" field in the table "ezpreferences" ).

To conclude, if the user country changes, we have to modify in real time the VAT value of prices on front office for the user connected. We understand that the fields value are storaged with the SPI api. So we modified your bundle to call the "simplePrice" runcallback function directly in the function "fromPersistenceValue". 

It is bit longer to get the value because the price field is always retrieved manually, but we must do that for our project.

Tkx very much for your help and your bundle !

Modified on Friday 23 January 2015 9:27:44 am by Clem PERISCOPE


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from