Jump to content

Display $product.price without currency


Recommended Posts

Hello,

 

Regarding SEO optimisation, I had to add some structured data by overriding modules.

To do so, I have to get the product price in several template (product.tpl, product-list.tpl, modules...).

 

But for one module, bockbestsellers, the displayed price is $product.price, and when I get its value I get "[Price] €".

 

Original code :

<span class="price">{$product.price}</span>

First try code :

<span class="price" itemprop="price">{$product.price}</span>

And I get this in google structured data test tool :

price: 1,94 €

 

With the following warning : The property is not a specification of valid price.

 

I know from my structured data in product.tpl that I need to put away the €. I only need numbers.

 

So I tried something that I saw on this forum :

{assign var='priceVar' value=$product.price}
<meta itemprop="price" content="{$priceVar|replace:' €':''}"/>

But it's not working.

 

Does someone can help me out on this problem ? I'm quite new handling smarty Prestashop template.

 

Additional information :

The var_dump result of $priceVar :

string '8,48 €'

In template product and product-list I do not have the problem because it seems $productPrice is already without currency.

And if I can avoid to modify the php of the module it would be great.

 

Thanks.

Edited by Gundi (see edit history)
  • Like 1
Link to comment
Share on other sites

Maybe coud be because in code appear

<meta itemprop="price" content="{$priceVar|replace:' €':''}"/>

and also something like this

<span class="price">{$product.price}</span>

and search engine is getting the {$product.price} instead of {$product.price|replace:' €:' '}"/>

 

I have tested in blockbestseller and the price appear without €

Edited by joselu (see edit history)
Link to comment
Share on other sites

Sorry, I don't completely understand what you trying to tell me.

 

You says that when you use blockbestseller, {$product.price} return the price without € ?

So maybe it's coming from the module parameters ?

 

Just in case, Here the whole div :

<div class="text_desc" itemprop="offers" itemscope itemtype="https://schema.org/Offer">
	<h5 class="float-left">
		<a href="{$product.link}" title="{$product.name|escape:'htmlall':'UTF-8'}" itemprop="url">
			{$product.name|strip_tags:'UTF-8'|escape:'htmlall':'UTF-8'|truncate:30:'...'}
		</a>
		<span class="price">{$product.price}</span>
		{assign var='priceVar' value=$product.price}
		{$priceVar|replace:' €':''}
		<meta itemprop="price" content="{$priceVar|replace:' €':''}"/>
		<meta itemprop="priceCurrency" content="EUR" />
	</h5>
</div>

I use another var than $product.price because of this thread: https://www.prestashop.com/forums/topic/437646-trying-to-get-total-price-in-blockcart-without-currency/

See post #6 and #8 from Nemo1.

 

Thank you for your time jllramos.

Edited by Gundi (see edit history)
Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 3 weeks later...

Sorry, am not tracking- Gundi. What exactly is your question? I followed whatever Grace provided in the answer and it worked. I still have to figure out how to get product review come up in the rich snippets but I dont have time to research that now.

Link to comment
Share on other sites

  • 4 months later...
  • 1 year later...
  • 1 year later...
  • 2 weeks later...

Thanks for the reply, actually, I am trying to strip out the £, but it doesn't seem to work.

I have tried the suggestions and I can get it to replace a number, so I know the code works, but it doesn't remove the £.

Link to comment
Share on other sites

On 4/18/2019 at 3:08 AM, djinni said:

Thanks for the reply, actually, I am trying to strip out the £, but it doesn't seem to work.

I have tried the suggestions and I can get it to replace a number, so I know the code works, but it doesn't remove the £.

Hi, sorry for delay...

What I did was to follow this link: 

and the comment of mysho.

the file I edited was: root/translations/cldr/main--it-IT--currencies (for you can be en-US or an other one)

for Euro you have to replace "symbol":"\u20ac" with "symbol":"EUR",

for GBP you have to replace "symbol":"\u00a3" with "symbol":"GBP",

etc...

 

then, of course, clean the cache and it should works.

You can have a look on my website: dailyshopbay

On my own, I add the currency at the end but on the Google webmasters tools, I only highlight the price without the currency and it maybe works!!

 

 

Edited by DailyShopBay (see edit history)
Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...
  • 4 years later...

<meta itemprop="price" content="{$product.price_amount}" />

Esta es buena y funciona, probado en 1.7.6 y 8.1

Lo añado como meta itemprop para enviar la información independiente a loq ue se ve en la tienda, en España se escriben los decimales con coma, no con punto. Además que la variable product.price muestra el formato que hayamos configurado: con coma y símbolo de euro o el que sea. $product.price_amount muestra solamente la cantidad sin símbolos y soluciona el problema

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...