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.


Tuesday 03 June 2014 2:22:58 pm

Hi. price fieldtype isn't available yet. I'm working in a bundle to allow because i also need this. Hopefully i'll be publishing some code in the next weeks. 

Tuesday 03 June 2014 2:27:59 pm

Thank for your response and to tell us when it is ok.


Good luck !

Friday 20 June 2014 9:00:55 am

Hi Carlos,

So, where have you got to ? ^^



Friday 20 June 2014 10:01:36 am

Hi there !

Turns out we (eZ) will collaborate with Carlos in order to offer native Price support. Our first objective is to get the basic Type, with its Value, Converter and template. It will offer support for simple prices, without VAT handling.

We will then iterate towards external storage, and add basic VAT support.

Would you maybe be interested in collaborating, even if it is just by testing and reviewing, Clem ?

Friday 20 June 2014 10:44:26 am

Hello Bertrand,

No problem to test and view ! But collaborating in the code, not the time unfortunately... sad.gif Emoticon

However, as we say, no problem to test a little and view because we need this for our project which works with ezshop extension. We hope that VAT will come soon because we need also happy.gif Emoticon



Friday 20 June 2014 10:55:25 am

Hi there. As Bertrand says, we're working on that. But i had some code wich you can use already. it is here


I had a solution in the very first steps of the history. If you checkout this commit https://github.com/crevillo/ezpricesbundle/commit/00f3c76c5b8e1240c07ffcb5f2f0693102dfac99

and maybe that could work for you.

What is done there is the converter, and for that i used a totally legacy code based solution. As a result it supports showing price including vats or discounts if the product has one. Which is not including is the l10n support, but maybe you can give a try.

Anyway that solution is not very elegant, and, well, soon or later we'll say goodbye to legacy stuff so it's time to do it in the proper way. We'll ping you about!.

Modified on Friday 20 June 2014 10:55:43 am by Carlos Revillo

Friday 20 June 2014 11:15:43 am

Yeah, ez6 will be the final solution happy.gif Emoticon

Tkx for the git. We will try this and give you our first impressions next week ! The best solution is to view this datatype completly in new stack but this is already good news for us and for our project with ezshop !

Tkx for all

Modified on Friday 20 June 2014 11:20:41 am by Clem PERISCOPE

Friday 20 June 2014 1:02:06 pm

Great!. Let me know if it helps happy.gif Emoticon.

Tuesday 24 June 2014 6:09:38 pm

Hi Carlos,

We have cloned the git and installed it in our project with the structure bellow for the bundle to work :

 src > Crevillos > EzPricesBundle

However, we have the error bellow when we clean the cache :

 PHP Fatal error:  Class 'Crevillo\EzPricesBundle\eZ\Publish\Core\FieldType\LegacyKernelStorage' not found in /var/www/....../src/Crevillo/EzPricesBundle/eZ/Publish/Core/FieldType/Price/PriceStorage.php on line 21

Indeed, there is not this class in the bundle. Is this a oversight ?



Tuesday 24 June 2014 6:18:18 pm

please note it should be src > Crevillo (without the ending s )

and remember also to checkout from the commit i pointed you in the previous message.

Tuesday 24 June 2014 6:34:06 pm

We do not understand. The line bellow does not work in the file "src/Crevillo/EzPricesBundle/eZ/Publish/Core/FieldType/Price/PriceStorage.php" :

 use Crevillo\EzPricesBundle\eZ\Publish\Core\FieldType\LegacyKernelStorage;

The "Crevillo\EzPricesBundle\eZ\Publish\Core\FieldType\LegacyKernelStorage" file does not exist in your bundle. What can we do ?

For the "s" in  the name of the Bundle, it is a mistake in our post.


Tkx for your help.

Wednesday 25 June 2014 9:35:11 am

As said, the bundle is not properly tested. which wich commit are you working? wiht the last one? let me know.

P.S. In order to not add more noise with this specific task to the forum, feel free to contact me by email or adding your issue in the github repo itself.

Monday 19 January 2015 11:09:16 am

Hi @crevillo,

We have another question on the bundle you have developped for the ezprice attribute.

The value of the price seems to be cached or to be stored somewhere. We want that the price value refreshed in real time because all the users have not the same VAT rules on the site.

Is there a solution to do that ?

Tkx for all

Modified on Monday 19 January 2015 11:09:58 am by Clem PERISCOPE

Monday 19 January 2015 11:12:32 am

afaik there's no specific cache for prices. you should be sure that the controller rendering the price does no cache the entire output...

Monday 19 January 2015 11:25:24 am


No there are no cache in the controller rendering. We have already check. 

When we put a var_dump in the the method "getSimplePrice(....)" of your bundle after empty the cache, the dump is displayed. After that, we display the page and we put a second time the "'var_dump", the dump is not displayed. It seems the "getSimplePrice" method is called only one time.


An idea maybe ?

Modified on Monday 19 January 2015 11:25:53 am by Clem PERISCOPE

Monday 19 January 2015 11:30:27 am

We use also the ProductCategoryBundle to get the inc_value_price with the category of the product :

 {{ product.getField('prix_ht').value.inc_vat_price|number_format(2) }}

Monday 19 January 2015 11:33:39 am

but couldn't it be the cache that ez5 adds by default? is that full view of your product or something? 

Monday 19 January 2015 11:47:32 am

Yep, it is the full view of our product. We put a twig operator ( {{ 'now'|date('Ymd His') }} )  to display the date, and the date change after refresh the page. To not have a cache on the view full, we do that in the controller of the full override :

 // Forward the request to the original ViewController        
// And get the response. Eventually alter it (here we change the smax-age for cache).        
$response = $this->get('ez_content')->viewLocation(            
return $response;

Monday 19 January 2015 11:49:18 am

It seems the price value is persisted.

Monday 19 January 2015 11:57:32 am

really can't tell, but it shouldn't be the idea... can you do the dump thing in the caller of getSimplePrice? 


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

36 542 Users on board!

Forums menu

Proudly Developed with from