Change presentation of PHP calculation in Ajax field using JQuery

1 year 10 months ago #329499 by Stanby
Thanks for the tips on creating a calculation and applying that as a negative promotion to make the pricing dynamic on plans. Now the presented price shows as -40.8 as an example and I'm trying to make it look like £40.80.

I have been attempting to use different ways to replace the - with £ in my templates custom code area, but nothing seems to work, am I placing the code in the wrong place? Any help is truly appreciated.

An example of the code I'm using is below (myid is not the actual id just an example):
<script>
let str = document.getElementById("myid").innerHTML; 
let res = str.replace(/-/g, "£");
document.getElementById("myid").innerHTML = res;
</script>

Please Log in to join the conversation.

1 year 10 months ago #329502 by krileon
The calculation field isn't intended to be actually displayed. Not sure what you mean by in ajax field. Are you just wanting to change its display in profile view to a price display?


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

1 year 10 months ago #329504 by Stanby
Yes, the calculation also displays the price and is affected by the questions asked, so, as is my understanding, the ajax integration tracks the field changes and presents the price.

I should have asked this in my other post, www.joomlapolis.com/forum/255-developer-members-support/244641-solved-conditional-plans#327966

The excellent advice you gave:

Now you'd create a promotion that uses the value of that field as its promotion value. This promotion should be an always applied one instead of a coupon code and should be conditioned to only apply to your 1 specific plan. This should result in the price dynamically increasing entirely based off whatever criteria you want in your code field, which you can freely add to or adjust whenever you like. This also means you only need to maintain 1 plan, 1 promotion, and 1 field.

If you want to show them the code field during registration you'll need to combine it with CB Core Fields Ajax and turn on its Update On for all the fields the code field depends on. This will allow its display during registration to refresh. So for example the Update On with the above should have cb_field1 and cb_field2 selected and when those fields values change the code field will update.

Please Log in to join the conversation.

1 year 10 months ago #329506 by krileon
Ok, the best way to do that then is to apply the formatting in the code field itself.

$price = 0;

if ( $user->get( 'cb_field1' ) == 'value1' ) {
    $price += 20; // add 20 to the price
}

if ( $user->get( 'cb_field2' ) == 'value2' ) {
    $price += 5; // add 5 to the price
}

if ( $reason === 'register' ) {
    return cbpaidMoney::getInstance()->renderPrice( $price, null ); // Return formatted price during registration
}

return -$price;

I believe that should work. During registration it should pass the price through CBSubs price renderer. I don't recommend enabling the field for profile view or profile edit though. It's possible to format it in profile edit, but will be complicated to do so in profile view since CBSubs Promotions uses the profile reason to pull a field value.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.415 seconds

Facebook Twitter LinkedIn