Jump to content
Gundi

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

Share this post


Link to post
Share on other sites
<meta itemprop="price" content="{$priceVar|replace:'$':''}"/>

 

Change $ to € and it work!

 

Use ' €' with space before €:

<meta itemprop="price" content="{$priceVar|replace:' €':''}"/>
Edited by joselu (see edit history)

Share this post


Link to post
Share on other sites

Joselu,

 

Thanks for the answer, but I made a mistake in my first post draw, I did write correctly in my code.

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

I edited my post. Sorry.

Share this post


Link to post
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)

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

Hi Gundi- did you get an answer, I am getting the same warning

 

offers
 
@type
Offer
warning
price
$830.00 (The property $830.00 is not a valid price specification.)
priceCurrency
USD

Share this post


Link to post
Share on other sites

Hello Dedandw,

 

I read your Google Thread, but I only see that you have been told to remove the "$".

I already know where the problem come from, and I didn't see, in your thread, how I can solve it. Did I misread ?

 

Thanks.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

smarty replace doesn't work with multibyte chars. Try the regex_replace

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

Share this post


Link to post
Share on other sites

For anyone wondering, for me on PS 1.6.0.14 it was on product.tpl 

Correct:

<span id="our_price_display" class="price" itemprop="price" content="{$productPrice|regex_replace:'/€/':' '}">{convertPrice price=$productPrice}</span>

Share this post


Link to post
Share on other sites

Hi all.

I know this is an old thread, but any idea why this doesn't work for £?
I've tried all sorts and am stuck.

Share this post


Link to post
Share on other sites
On 4/7/2019 at 10:39 PM, djinni said:

Hi all.

I know this is an old thread, but any idea why this doesn't work for £?
I've tried all sorts and am stuck.

Hi djinni,

 

try to replace £ with GBP, I did the same from € to EUR.

Share this post


Link to post
Share on other sites

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 £.

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

Try to use $product.price_amount as variable for price without currency sign

  • Like 1

Share this post


Link to post
Share on other sites
On 6/4/2019 at 2:57 PM, aurelius7 said:

Try to use $product.price_amount as variable for price without currency sign

That works for me in 1.7.6 in the catalogue/_partials/product-prices.tpl

Put {$product.price_amount} in stead of the {$product.price}

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More