Skip to Content Skip to Menu

[SOLVED] CB Sub based on Field Groups - is this possible?

5 years 5 months ago - 5 years 5 months ago #312643 by matt@harrington.co.nz
[SOLVED] CB Sub based on Field Groups - is this possible? was created by matt@harrington.co.nz
Happy Wednesday all,

I am looking at setting up a subscription based on the number of fields that are added to a CB Field Group.

For instance 1 member signs up his family for a membership at $10 each. He has four family members so adds his family members (3) to a field group with their names. The plan then comes to $40 for four members.

Is this possible? I haven't played with Field Groups much yet but can't see the functionality off the shelf.

Thanks in advance, Matt
Last edit: 5 years 5 months ago by krileon. Reason: Added [SOLVED] tag to subject

Please Log in or Create an account to join the conversation.

5 years 5 months ago #312644 by matt@harrington.co.nz
Replied by matt@harrington.co.nz on topic CB Sub based on Field Groups - is this possible?
Hmmm. This looks like what I might need here:

www.joomlapolis.com/forum/277-cb-paid-subscriptions-support/240972-a-single-user-with-multiple-subscriptions-of-the-same-subscription#312331

I'll take a look at this and see if it will work for my use case.

Please Log in or Create an account to join the conversation.

5 years 5 months ago - 5 years 5 months ago #312645 by matt@harrington.co.nz
Replied by matt@harrington.co.nz on topic CB Sub based on Field Groups - is this possible?
OK. I'm stuck. I have a field group and would like to count the number of adults to apply a promotion (in this case add to invoice) but am not sure I am referencing the fields correctly.

Attached are screenshots of my fields and their associated fields. The code field returns the value 0 at all times.

CB Code below:
Code:
$adult = 0; $price = 0; foreach ( json_decode( '[cb_familymembers]', true ) as $child ) { if ( $child['cb_familymembers_adultvisitor'] == 'Adult' ) { $adult++; } } if ( $adult ) { $price += ( $adult * 10 ); } return $price;
Attachments:
Last edit: 5 years 5 months ago by matt@harrington.co.nz.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • OFFLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
5 years 5 months ago #312670 by krileon
You're checking if the value of cb_adultvisitor in a field group is Adult. Is the value for the select option actually Adult or something else? Edit cb_adultvisitor within CB > Field Management and ensure you're matching against Value and not Label. You can add a var_dump in your code to see what the $child contains as well (e.g. var_dump( $child ) just before your IF statement).


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 or Create an account to join the conversation.

5 years 5 months ago #312680 by matt@harrington.co.nz
Replied by matt@harrington.co.nz on topic CB Sub based on Field Groups - is this possible?
Thanks Krileon,

I have a vardump of the array but still cannot seem to get the function to return the number of adults. Here is the array the vardump returns:
Code:
array(2) { ["cb_adultvisitor"]=> string(5) "Adult" ["cb_familymembername"]=> string(3) "Bob" } array(2) { ["cb_adultvisitor"]=> string(5) "Adult" ["cb_familymembername"]=> string(6) "Sharon" } array(2) { ["cb_adultvisitor"]=> string(5) "Child" ["cb_familymembername"]=> string(7) "Michael" }

Please Log in or Create an account to join the conversation.

5 years 5 months ago #312681 by matt@harrington.co.nz
Replied by matt@harrington.co.nz on topic [SOLVED] CB Sub based on Field Groups - is this possible?
Aha. Fixed it. Awesome.

Code should be:
Code:
$adult = 0; $price = 0; foreach ( json_decode( '[cb_familymembers]', true ) as $child ) { if ( $child['cb_adultvisitor'] == "Adult" ) { $adult++; } } return $adult;
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum