Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

microdata "price" in product_listing.php


cupidare

Recommended Posts

Hello, 

 

Sorry for this silly question, but I struggle with this: 

 

in product_listing.php 

          $prod_list_contents .= '      <div class="col-xs-6" itemprop="offers" itemscope itemtype="http://schema.org/Offer"><meta itemprop="priceCurrency" content="' . tep_output_string($currency) . '" /><div class="btn-group" role="group"><button type="button" class="btn btn-default"><span itemprop="price" content="' . preg_replace('/[^0-9.]*/', '', $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id']))) . '">' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></button></div></div>';

How can I convert a different price-separation (in my case "," instead of "." e.g. 2,70€) to a 2.70 for the microdata? At the moment the preg_replace gives for this example

 

content="270.."

 

thank you in advance ...

Link to comment
Share on other sites

What string does $currencies->display_price(...) give you? Is it 2,70€ (German-style , decimal separator) and you want 2.70 or 2.70€? If you want the latter, and you know there will be (at most) one comma, how about something like

preg_replace('/,/', '.', $currencies->...

If you want to get rid of the Euro, too, the substitutions require arrays:

preg_replace(array('/,/', '/€/'), array('.', ''), $currencies->...

(or something like that) might work. preg_replace() may be overkill for something like this, and you could use str_replace().

Link to comment
Share on other sites

thank you for your reply. 

 

I changed it to 

preg_replace(array('/[^0-9,0-9]/','/[,]/'),array('','.')

which works for me. I don't know, if this is overkill... The problem is that google wants the price in the format 2.70 without comma or currency...

Link to comment
Share on other sites

My suggestion was that the use of preg_replace() was overkill, and that str_replace() would be much faster and easier to understand. All you're doing is substituting . for , and <null> for €, neither of which require regular expression pattern matching.

 

By the way, your pattern [^0-9,0-9] doesn't do what you think it does. It matches anything not digit or comma (in your case, the Euro sign), not a pattern digit,digit. And a single character to match shouldn't be [,], but just , . You need to study up on regular expression pattern matching before you get yourself in trouble.

Link to comment
Share on other sites

Hello Gary, 

 

I implemented this and it works very well. Although I omitted the index_nested stuff (not in my version) I got no errors in the product_listing from the structured data test  (product: no error, breadcrumb: no error)

 

thank you a lot. Am I right in applying this to product_info and all the other sites?

 

Thank you a lot!

Link to comment
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...