Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Adding a Comma

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 04-01-2021, 10:32 AM
  Blainevk's Avatar 
Blainevk Blainevk is offline
 

Senior Member
  
Join Date: Dec 2004
Location: Atlanta, GA
Posts: 162
 

Default Adding a Comma

Hello X-cart 5 Community,

I want to add a comma to a number that I created from the Price of all items in my Mall. See image below for detailed description...



Thanks in advance for your help,
Blaine.
Attached Thumbnails
Click image for larger version

Name:	****giftmall_comma_pic.png
Views:	1529
Size:	172.9 KB
ID:	5632  
__________________
Blaine

X-Cart Multi-vendor 5.4.1.35
PHP version: 8.1

Blaine's Travel Club - http://blainestravelclub.com

Collect Travel Points - http://blainestravelclub.com/travelpoints/rewards/

Travel Points Gift Mall - https://blainestravelclub.com/travelpoints/giftmall/

Grow Your Business - http://blainestravelclub.com/business/

Making Money & Fun - http://blainestravelclub.com/travelers/

Charitable Fun-razing - http://blainestravelclub.com/fun-razors
Reply With Quote
  #2  
Old 04-01-2021, 11:25 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,197
 

Default Re: Adding a Comma

You can use the PHP format_number


https://php.net/manual/en/function.number-format.php


If it doesn't work directly in the twig file set new method to use it and return the formatted value
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #3  
Old 04-01-2021, 02:33 PM
  Blainevk's Avatar 
Blainevk Blainevk is offline
 

Senior Member
  
Join Date: Dec 2004
Location: Atlanta, GA
Posts: 162
 

Default Re: Adding a Comma

Thanks Steve,

But this is all GREEK to me, how much would you charge me to make this work?
__________________
Blaine

X-Cart Multi-vendor 5.4.1.35
PHP version: 8.1

Blaine's Travel Club - http://blainestravelclub.com

Collect Travel Points - http://blainestravelclub.com/travelpoints/rewards/

Travel Points Gift Mall - https://blainestravelclub.com/travelpoints/giftmall/

Grow Your Business - http://blainestravelclub.com/business/

Making Money & Fun - http://blainestravelclub.com/travelers/

Charitable Fun-razing - http://blainestravelclub.com/fun-razors
Reply With Quote
  #4  
Old 04-01-2021, 07:18 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,197
 

Default Re: Adding a Comma

You just have to do what you already did but use the format_number function.
Where you added {{ (this.getListPrice() * 1000) +0 }} replace it with

{{ format_number($this.getListPrice() * 1000) }}

The function uses as default 0 decimals, dot as decimal separator and comma as thousands separator so the above will effectively return

123,450 (if list price is say $123.45)


Doing this with php method to use in the twig file will require you to have custom module and define the method to use which will essentially do the same.
I can code this for you if you want to but I just don't see the need for it when you can replace it within the template with the code I provided here, just like you already did with your own version.


However if you don't feel like doing this or want to expand on it you can contact me with details and I can get it done for you. Just open a ticket at support.cflsystems.com
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #5  
Old 04-03-2022, 05:05 PM
  Blainevk's Avatar 
Blainevk Blainevk is offline
 

Senior Member
  
Join Date: Dec 2004
Location: Atlanta, GA
Posts: 162
 

Default Re: Adding a Comma

Steve,

(Sorry I NEVER received an email that you answered my question, it wasn't until today that I was looking at the forum and discovered your answer)

So, I tried replacing the old with yours... {{ format_number($this.getListPrice() * 1000) }}

but it does not seem to work...

I GET THIS ERROR...

Unexpected character "$" in "theme_tweaker/customer/modules/XC/ProductVariants/price_range.twig" at line 8.

Then I deleted the "$" and tried saving it agein, then I get this error...

Unknown "format_number" function in "theme_tweaker/customer/modules/XC/ProductVariants/price_range.twig" at line 8.

In case it makes a difference or you didn't notice, I'm using MultivenderXC5
__________________
Blaine

X-Cart Multi-vendor 5.4.1.35
PHP version: 8.1

Blaine's Travel Club - http://blainestravelclub.com

Collect Travel Points - http://blainestravelclub.com/travelpoints/rewards/

Travel Points Gift Mall - https://blainestravelclub.com/travelpoints/giftmall/

Grow Your Business - http://blainestravelclub.com/business/

Making Money & Fun - http://blainestravelclub.com/travelers/

Charitable Fun-razing - http://blainestravelclub.com/fun-razors
Reply With Quote
  #6  
Old 04-04-2022, 04:49 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,197
 

Default Re: Adding a Comma

Sorry should be "number_format" and yes there is no $
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #7  
Old 04-05-2022, 09:14 AM
  Blainevk's Avatar 
Blainevk Blainevk is offline
 

Senior Member
  
Join Date: Dec 2004
Location: Atlanta, GA
Posts: 162
 

Default Re: Adding a Comma

Hi Steve,

Sorry, but "number_format" does not work?

ERROR:
Unknown "number_format" function in "theme_tweaker/customer/common/price_parts/price.twig" at line 3.
__________________
Blaine

X-Cart Multi-vendor 5.4.1.35
PHP version: 8.1

Blaine's Travel Club - http://blainestravelclub.com

Collect Travel Points - http://blainestravelclub.com/travelpoints/rewards/

Travel Points Gift Mall - https://blainestravelclub.com/travelpoints/giftmall/

Grow Your Business - http://blainestravelclub.com/business/

Making Money & Fun - http://blainestravelclub.com/travelers/

Charitable Fun-razing - http://blainestravelclub.com/fun-razors
Reply With Quote
  #8  
Old 04-06-2022, 08:11 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,197
 

Default Re: Adding a Comma

Apparently you cannot call php functions directly in twig files. You can try this as modifier



{{ ($this.getListPrice() * 1000)|number_format() }}
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #9  
Old 04-09-2022, 11:31 AM
  Blainevk's Avatar 
Blainevk Blainevk is offline
 

Senior Member
  
Join Date: Dec 2004
Location: Atlanta, GA
Posts: 162
 

Default Re: Adding a Comma

Hi Steve,

I held my breath, clicked SAVE... and IT WORKED!!!!!!!

Thanks so much, you were the only one who took the time to help me "add a comma", I've been trying off & on for over 2 years to add a simple comma, which turned out to be not so simple. LOL

Check it out: https://blainestravelclub.com/travelpoints/giftmall/
__________________
Blaine

X-Cart Multi-vendor 5.4.1.35
PHP version: 8.1

Blaine's Travel Club - http://blainestravelclub.com

Collect Travel Points - http://blainestravelclub.com/travelpoints/rewards/

Travel Points Gift Mall - https://blainestravelclub.com/travelpoints/giftmall/

Grow Your Business - http://blainestravelclub.com/business/

Making Money & Fun - http://blainestravelclub.com/travelers/

Charitable Fun-razing - http://blainestravelclub.com/fun-razors
Reply With Quote
  #10  
Old 04-11-2022, 03:18 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,197
 

Default Re: Adding a Comma

Good to know it finally worked for you
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 04:22 PM.

   

 
X-Cart forums © 2001-2020