Copy link to clipboard
Copied
I have developed a web site for a real estate agency for which I have built a custom web app. The web app has a number fields that display information about individual properties in both list and detail formats. Some of the fields I created in the web app are "number" fields. I used number fields for price and square feet because I also have a search form linked to the web app. I needed to have a min and max search capability for these two fields, which the "number" field provides automatically. However, being a "number" field, it does not allow for the use of commas in the field, which is a client requirement. If a comma is used in the web app field, the display is null. For example, the client needs the price to be displayed like this (1,300,000) vs (1300000). Here is a link to the test site: Anne Rogers Realty Group, Inc - Featured Listings. Note the price and square feet fields on both the list an detail views for the properties. Is there any way around this problem? Thanks in advance
Hi Murray,
Business Catalyst is not PHP based, nor do you have access to server side code. It does not work like that so you cant do that.
For the original poster - If you really need them to be numbers for the search you only have a few options..
- Enable the beta liquid feature and use that to manipulate the output
- Do it with javascript
- Leave it as is
- Create text fields of the prices as well for display and the number fields for search.
Copy link to clipboard
Copied
Why can't you put the commas in for display, and remove them on submit?
Something like - $number = 1234.56; echo number_format($number,2,'.','.');
//string number_format ( float $number , int $decimals = 0 , string $dec_point = "." , string $thousands_sep = "," )
And then on submit, str_replace(',','',$_POST[numberField])
Would that work?
Copy link to clipboard
Copied
Hi Murray,
Business Catalyst is not PHP based, nor do you have access to server side code. It does not work like that so you cant do that.
For the original poster - If you really need them to be numbers for the search you only have a few options..
- Enable the beta liquid feature and use that to manipulate the output
- Do it with javascript
- Leave it as is
- Create text fields of the prices as well for display and the number fields for search.
Copy link to clipboard
Copied
Thanks, Liam. I missed that completely!
Copy link to clipboard
Copied
Thanks Liam. Looks like creating text fields of the prices as well for display and the number fields for search is the way to go to accomplish what I needed. Why didn't I think of that!?
Copy link to clipboard
Copied
Well you can do anything from developer's perspective but asking client to put same value twice can make you look unprofessional.
Here's what I did for many house listing websites.
1. Client puts price in pure number format ( e.g. 500000 )
2. wrap the price value with a tag in List/Detail template e.g. <span class="house-price">{tag_price}</span>
3. then at the end of the page put a jQuery snippet which would globally format the prices ( e.g. $('.house-price').formatCurrency(); )
Here's one I use
https://code.google.com/p/jquery-formatcurrency/
even if you're not familiar with jQuery it's pretty easy to follow
No more complain from client
Copy link to clipboard
Copied
Or you use liquid now and use data types and not have to do that
Copy link to clipboard
Copied
Great Liam! And now, could you explain us exactly how you would do that?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks Liam!
Copy link to clipboard
Copied
I'm using liquid to format my number to the currency format. However the commas are not showing up. Is there a way to force it to show?
Shopify has custom formats like money_with_comma_seperators, however I do not think BC has this..
Copy link to clipboard
Copied
Depending on currency, since BC runs its prices on culture would be your to manage where you split and display as you need to and that is quite straight forward.
Liquid is data and its just data so its up to use to use it and display as we need. It wont happen like magic like tags
Copy link to clipboard
Copied
Edit:
I've tried:
currency: USD
currency: 'USD'
convert:'USD'
and they couldn't work.
Do I have to use javascript to do the splitting instead?
So if I wanted to display it as USD then I would do it as {{price | currency:USD | remove: '.00'}}?
Copy link to clipboard
Copied
You need to read the BC documentation:
Currency does not work like that and how your using it.
You need to use the split filter and manipulate as you need to etc.. Use what is documented, not anything else.
Copy link to clipboard
Copied
Ok thanks for the clarification!! 😃
Copy link to clipboard
Copied
{% if this.price > 999999 %}
<span class="price">{{price | divided_by: 1000000 | currency | remove: '.00'}},{{price | modulo:1000000 | divided_by:100000}}{{price | modulo:100000 | divided_by:10000}}{{price | modulo:10000 | divided_by:1000}},{{price | modulo:1000 | divided_by:100}}{{price | modulo:100 | divided_by:10}}{{price | modulo:10 | divided_by:1}}
{% elseif this.price > 999 %}
<span class="price">{{price | divided_by: 1000 | currency | remove: '.00'}},{{price | modulo:1000 | divided_by:100}}{{price | modulo:100 | divided_by:10}}{{price | modulo:10 | divided_by:1}}
{% else %}
<span class="price">{{price | currency | remove: '.00'}}
{% endif %}
Here's the code.. If anyone is interested
Copy link to clipboard
Copied
That is first round, go through it again and you can simplify that a lot, Like I said, split is one element for that.