Hi,
I am trying to develop an online registration system for a swim club. I have successfully developed a multipage form that contains all of the parts of registration and upon submit the user is redirected to a page where they can add their fees to a shopping cart (using simple caddy). My multipage form works fine, My shopping cart works fine, but now I am wondering if there is a way that I can use ChronoForms to automatically populate the shopping cart with the fees associated with the items for which the member has registered.
To my knowledge there is not a way for the cart to "get" data from a table, but there is a way of adding items to the cart with a URL like this: index.php?option=com_caddy&action=addtocart&edtitemcode=yourcode&edtqty=1&edtoption=xyz&edtsh
I want to add many items at one time, and use the redirect URL as: index.php?option=com_caddy&action=showcart&Itemid=104
so on submit of the form the member is taken directly to the cart with whatever qty of swim team, dive team, lesson sessions, etc., already added to the cart.
I am sure there is a some way to do this, while I am not afraid to dissect and alter php, I am a newbie, and not sure where to start. Any help will be greatly appreciated.
I am trying to develop an online registration system for a swim club. I have successfully developed a multipage form that contains all of the parts of registration and upon submit the user is redirected to a page where they can add their fees to a shopping cart (using simple caddy). My multipage form works fine, My shopping cart works fine, but now I am wondering if there is a way that I can use ChronoForms to automatically populate the shopping cart with the fees associated with the items for which the member has registered.
To my knowledge there is not a way for the cart to "get" data from a table, but there is a way of adding items to the cart with a URL like this: index.php?option=com_caddy&action=addtocart&edtitemcode=yourcode&edtqty=1&edtoption=xyz&edtsh
I want to add many items at one time, and use the redirect URL as: index.php?option=com_caddy&action=showcart&Itemid=104
so on submit of the form the member is taken directly to the cart with whatever qty of swim team, dive team, lesson sessions, etc., already added to the cart.
I am sure there is a some way to do this, while I am not afraid to dissect and alter php, I am a newbie, and not sure where to start. Any help will be greatly appreciated.
Hi Apryl,
I don't know SimpleCaddy (looks interesting though). You could possibly write directly to the SimpleCaddy tables or perhaps safer, use CURL to run inside a loop and add many items for you.
The CURL plugin only works for a single item. but you could adapt the plugin code to run inside a loop in the OnSubmit After box.
Bob
I don't know SimpleCaddy (looks interesting though). You could possibly write directly to the SimpleCaddy tables or perhaps safer, use CURL to run inside a loop and add many items for you.
The CURL plugin only works for a single item. but you could adapt the plugin code to run inside a loop in the OnSubmit After box.
Bob
[attachment=0]regform.png[/attachment]Thank you Bob,
I will definitely look into using the curl plugin. I am new to a lot of this so I will try to ask specific questions.
before I solve my issue of how to pass information to simplecaddy, I need to compile some info in my forms possibly using hidden fields. My form is designed so a parent can register all of their children on one page for various teams as well as swim lessons. I am attaching a copy here so you can see. Swim lessons are $35 per session. If someone has 3 kids who want to take lessons during all 4 sessions, then the quantity I want to add to the cart is 12. But the check boxes all have different IDs (swimmer 1 session 1 is sw1_s1, swimmer 2 session 4 is sw2_s4, and so on). How can I use a hidden field to add the number of all the session boxes that are checked on the registration form? I don't need to know what session or what swimmer, just the number of checked boxes.
Simplecaddy unlike other carts lets you define products and them place them within pages without your typical shopping cart environment. For instance I can place an image of a product in any content item and then put {simplecaddy code=swimlessons} and that places my defined product description and an add to cart button.
Basically, I want to use a hidden field to determine the number of sessions and then submit the URL "index.php?option=com_caddy&action=addtocart&edtitemcode=swimlessons&edtqty=12
Can you help with this?
Apryl
I will definitely look into using the curl plugin. I am new to a lot of this so I will try to ask specific questions.
before I solve my issue of how to pass information to simplecaddy, I need to compile some info in my forms possibly using hidden fields. My form is designed so a parent can register all of their children on one page for various teams as well as swim lessons. I am attaching a copy here so you can see. Swim lessons are $35 per session. If someone has 3 kids who want to take lessons during all 4 sessions, then the quantity I want to add to the cart is 12. But the check boxes all have different IDs (swimmer 1 session 1 is sw1_s1, swimmer 2 session 4 is sw2_s4, and so on). How can I use a hidden field to add the number of all the session boxes that are checked on the registration form? I don't need to know what session or what swimmer, just the number of checked boxes.
Simplecaddy unlike other carts lets you define products and them place them within pages without your typical shopping cart environment. For instance I can place an image of a product in any content item and then put {simplecaddy code=swimlessons} and that places my defined product description and an add to cart button.
Basically, I want to use a hidden field to determine the number of sessions and then submit the URL "index.php?option=com_caddy&action=addtocart&edtitemcode=swimlessons&edtqty=12
Can you help with this?
Apryl
Hi Apryl,
I'd add a little JavScript to keep count of the checked boxes and put the total into a hidden input. You could do the same with PHP after the form is submitted; then create an appropriate ReDirect url and the job is done.
Bob
I'd add a little JavScript to keep count of the checked boxes and put the total into a hidden input. You could do the same with PHP after the form is submitted; then create an appropriate ReDirect url and the job is done.
Bob
Hi Bob,
Thanks for the great advice.
I have used javascript to count four sets of checkboxes in my form and display them in total boxes at the bottom of the form. Then I am using the profile plugin to pass the values of those four fields to another form that I have on the same article page as my simpleCaddy product items. I couldn't figure out how to write the code to pass the information to simplecaddy to automatically populate the cart, but at least the parents can now see what they registered for and what items they need to add to the cart.
[attachment=1]cartSS.png[/attachment]
My problem is that when I use the profile plugin no matter how many times I fill out the registration form only the values of the first record I made are passed. I am attaching a screenshot of my cart page and also of my profile plugin settings.
[attachment=0]profileplug.png[/attachment]
Is there any way that the profile plugin can pass the values of the most current record made by the user and not the first one? With the way things are working now, if a parent registers Three Children, and then comes back to register another one at a different time, they are told that they need to pay for the three child registration.
Many Thanks,
Apryl
Thanks for the great advice.
I have used javascript to count four sets of checkboxes in my form and display them in total boxes at the bottom of the form. Then I am using the profile plugin to pass the values of those four fields to another form that I have on the same article page as my simpleCaddy product items. I couldn't figure out how to write the code to pass the information to simplecaddy to automatically populate the cart, but at least the parents can now see what they registered for and what items they need to add to the cart.
[attachment=1]cartSS.png[/attachment]
My problem is that when I use the profile plugin no matter how many times I fill out the registration form only the values of the first record I made are passed. I am attaching a screenshot of my cart page and also of my profile plugin settings.
[attachment=0]profileplug.png[/attachment]
Is there any way that the profile plugin can pass the values of the most current record made by the user and not the first one? With the way things are working now, if a parent registers Three Children, and then comes back to register another one at a different time, they are told that they need to pay for the three child registration.
Many Thanks,
Apryl
Hi Apryl,
Hmmm, the profile plugin is only designed to pick up one record from the database and it is doing that by picking up the first record with the correct value of cf_user_id.
If you want to show more than one record then you'll need to use ChronoConnectivity to display a list; or better, use a little form with a MySQL query to pick up all the records and show them in a table.
Linking to Simple Caddy might be possible using a script to link some values, or with some PHP to tie the two together but I suspect that's not trivial.
Bob
Hmmm, the profile plugin is only designed to pick up one record from the database and it is doing that by picking up the first record with the correct value of cf_user_id.
If you want to show more than one record then you'll need to use ChronoConnectivity to display a list; or better, use a little form with a MySQL query to pick up all the records and show them in a table.
Linking to Simple Caddy might be possible using a script to link some values, or with some PHP to tie the two together but I suspect that's not trivial.
Bob
Hi Bob,
Linking directly to simple caddy is the optimal choice but I am not very skilled at writing code, but somewhat okay at modifying already written examples to fit my needs. Which is why I LOVE Chronoforms because it does a lot of the heavy lifting for me.
If there were only one product I could make the redirect url as follows and add my product to the cart:
index.php?option=com_caddy&action=addtocart&name="addtocart1"&edtprodcode=st1&edtshorttext=SwimTeamFees&edtunitprice=60&edtqty=1
But I need 3 other products:
index.php?option=com_caddy&action=addtocart&name="addtocart2"&edtprodcode=dt1&edtshorttext=DiveTeamFees&edtunitprice=60&edtqty=1
index.php?option=com_caddy&action=addtocart&name="addtocart3"&edtprodcode=yt1&edtshorttext=SynchroTeamFees&edtunitprice=60&edtqty=1
index.php?option=com_caddy&action=addtocart&name="addtocart4"&edtprodcode=l11&edtshorttext=SwimlessionFees&edtunitprice=60&edtqty=1
And now that I have my Javascript that counts the check boxes I need to some how replace 'edtqty' for each item with the values '{totalswim}' '{totaldive}' '{totalsynchro}' and '{totalsession}'
but it sounds like the profile plugin is not the way to go.
I have also tried to change the submit url to: index.php?option=com_caddy
and the redirect url to: index.php?option=com_caddy&action=showcart
and use something like:
But that is as far as I got before realizing I may be in over my head.
I understand that this forum is for issues with the component and plug ins and not for requesting help writing code, but I will happily make a donation if you can help me to get this to work and stay in the good graces of my client who is running out of patience.
Thank you,
Apryl
(sorry for the superlong post)
Linking directly to simple caddy is the optimal choice but I am not very skilled at writing code, but somewhat okay at modifying already written examples to fit my needs. Which is why I LOVE Chronoforms because it does a lot of the heavy lifting for me.
If there were only one product I could make the redirect url as follows and add my product to the cart:
index.php?option=com_caddy&action=addtocart&name="addtocart1"&edtprodcode=st1&edtshorttext=SwimTeamFees&edtunitprice=60&edtqty=1
But I need 3 other products:
index.php?option=com_caddy&action=addtocart&name="addtocart2"&edtprodcode=dt1&edtshorttext=DiveTeamFees&edtunitprice=60&edtqty=1
index.php?option=com_caddy&action=addtocart&name="addtocart3"&edtprodcode=yt1&edtshorttext=SynchroTeamFees&edtunitprice=60&edtqty=1
index.php?option=com_caddy&action=addtocart&name="addtocart4"&edtprodcode=l11&edtshorttext=SwimlessionFees&edtunitprice=60&edtqty=1
And now that I have my Javascript that counts the check boxes I need to some how replace 'edtqty' for each item with the values '{totalswim}' '{totaldive}' '{totalsynchro}' and '{totalsession}'
but it sounds like the profile plugin is not the way to go.
I have also tried to change the submit url to: index.php?option=com_caddy
and the redirect url to: index.php?option=com_caddy&action=showcart
and use something like:
<p>Swim Team Fee</p><input value="add to cart" type="submit" /> <input name="option" value="com_caddy" type="hidden" /> <input name="action" value="addtocart" type="hidden" /> <input name="edtprodcode" value="st1" type="hidden" /> <input name="edtshorttext" value="Swim Team" type="hidden" /> <input name="edtunitprice" value="60" type="hidden" /> <input name="edtqty" value="1" type="hidden" />
But that is as far as I got before realizing I may be in over my head.
I understand that this forum is for issues with the component and plug ins and not for requesting help writing code, but I will happily make a donation if you can help me to get this to work and stay in the good graces of my client who is running out of patience.
Thank you,
Apryl
(sorry for the superlong post)
Hi Apryl,
I've taken a look at the Simple Caddy code and I think it may be possible to high-jack some of that to do the addCart actions - will take a me a day or so to find the time to test it though.
Bob
I've taken a look at the Simple Caddy code and I think it may be possible to high-jack some of that to do the addCart actions - will take a me a day or so to find the time to test it though.
Bob
Hi Apryl,
This is more or less working. I've added the following code to the OnSubmit After box of your form
[attachment=0]19-03-2010 11-26-44.png[/attachment]
The fourth entry has the right number of lesson sessions showing but isn't matched to a product because I counted the total sessions and you have several different session products set up. You can easily clean this up.
The code works but there's probably quite a bit of fine tuning and error checking required to make it properly robust.
Bob
This is more or less working. I've added the following code to the OnSubmit After box of your form
<?php
require_once(JPATH_SITE.DS.'components'.DS.'com_caddy'.DS.'caddy.cart.class.php');
require_once(JPATH_SITE.DS.'components'.DS.'com_caddy'.DS.'caddy.class.php');
$swtm_array = $dwtm_array = $sytm_array = $lses_array = array();
for ( $i = 0; $i <= 5; $i++ ) {
$swtm_array[$i] = JRequest::getBool('swtm'.$i, 'false', 'post');
$dwtm_array[$i] = JRequest::getBool('dwtm'.$i, 'false', 'post');
$sytm_array[$i] = JRequest::getBool('sytm'.$i, 'false', 'post');
}
for ( $i = 0; $i <= 23; $i++ ) {
$lses_array[$i] = JRequest::getBool('lses'.$i, 'false', 'post');
}
$count['st1'] = array_sum($swtm_array);
$count['dt1'] = array_sum($dwtm_array);
$count['yt1'] = array_sum($sytm_array);
$count['lses'] = array_sum($lses_array);
$products = new products();
foreach ( $count as $k => $v ) {
$p = $products->getproductByProdCode($k);
$p->option = '';
$p->formula = '';
$p->caption = '';
$p->quantity = $v;
$p->prodname = $p->shorttext;
$p->finalprice = $p->unitprice;
$cart2 = new cart2();
$cart2->addCartProduct($p);
}
?>
and after the form is submitted the products are added to the Cart:[attachment=0]19-03-2010 11-26-44.png[/attachment]
The fourth entry has the right number of lesson sessions showing but isn't matched to a product because I counted the total sessions and you have several different session products set up. You can easily clean this up.
The code works but there's probably quite a bit of fine tuning and error checking required to make it properly robust.
Bob
Bob,
You are brilliant! Thank you so much for this. I know I have a lot of fine tuning to do, but this is perfect and will make my client so happy to know there is a solution in the works. I would love to buy you dinner, where can I make a donation?
Gratefully yours,
Apryl
You are brilliant! Thank you so much for this. I know I have a lot of fine tuning to do, but this is perfect and will make my client so happy to know there is a solution in the works. I would love to buy you dinner, where can I make a donation?
Gratefully yours,
Apryl
Bob,
I changed my product code for the lesson sessions and have managed to get most everything working. There is only one problem I have found so far. If a value of 0 is passed to the cart I get an error when posting to paypal. If at least one of each of the four items is purchased there is no error.
Here is the error:
You have entered an invalid quantity value. A quantity value must be an integer greater than or equal to one.
I am going to tinker around a bit and see if I can figure it out, but if you have any suggestions I would love to hear them.
Thanks,
Apryl
I changed my product code for the lesson sessions and have managed to get most everything working. There is only one problem I have found so far. If a value of 0 is passed to the cart I get an error when posting to paypal. If at least one of each of the four items is purchased there is no error.
Here is the error:
You have entered an invalid quantity value. A quantity value must be an integer greater than or equal to one.
I am going to tinker around a bit and see if I can figure it out, but if you have any suggestions I would love to hear them.
Thanks,
Apryl
Hi Apryl,
Good catch, I think you just need to break out of the loop if the quantity is zero
Bob
Good catch, I think you just need to break out of the loop if the quantity is zero
foreach ( $count as $k => $v ) {
if ( $v <= 0 ) {
continue;
}
$p = $products->getproductByProdCode($k);
. . .
Bob
Hi Bob,
I tried that and a few variations but it results in nothing being added to the cart.
What about an if...else... where if adds to cart, and else removes item from cart?
I don't have this quite right, but I am basing this off of what you have done and in looking at the simple caddy code here:
Thank you,
Apryl
I tried that and a few variations but it results in nothing being added to the cart.
What about an if...else... where if adds to cart, and else removes item from cart?
$products = new products();
foreach ( $count as $k => $v ){
if ($v => 0)
$p = $products->getproductByProdCode($k);
$p->option = '';
$p->formula = '';
$p->caption = '';
$p->quantity = $v;
$p->prodname = $p->shorttext;
$p->finalprice = $p->unitprice;
$cart2 = new cart2();
$cart2->addCartProduct($p);
}
else
{
$p = $products->getproductByProdCode($k);
$p->option = '';
$p->formula = '';
$p->caption = '';
$p->quantity = $v;
$p->prodname = $p->shorttext;
$p->finalprice = $p->unitprice;
$cart2 = new cart2();
$cart2->removeCartProduct($p);
}
?>
I don't have this quite right, but I am basing this off of what you have done and in looking at the simple caddy code here:
function removeCartProduct($p) {
$cartArray=$this->readCart();
$todelete=false;
if (count($cartArray)>0) {
foreach ($cartArray as $key=>$prod) {
if (($prod->prodcode == $p->prodcode) and ($prod->option==$p->option)) {
$prod->quantity = $prod->quantity-1;
if ($prod->quantity==0) { // nothing left
$todelete=true;
$which=$key;
break; // we have found the producty, no need to do the rest
}
}
}
if ($todelete) {
array_splice($cartArray, $key, 1);
}
}
$cartXML=$this->makeCartXML($cartArray);
$this->writeCart($cartXML);
return $cartXML;
}
Or is there something that can be run in the extra code boxes that would remove an item with qty 0 after the onsubmit after email is run? Another possibility could be to alter the scpaypal.class.php file in simplecaddy to not post anything with a qty=0, but I am not sure how difficult that would be.Thank you,
Apryl
Hi Apryl,
The code I posted works OK when I test it here . . .
I'll take a look at your site.
Bob
The code I posted works OK when I test it here . . .
I'll take a look at your site.
Bob
Great I will back out of there for a minute so you can check things out. I was altering some things but think I have it back to normal. Is is possible that what I have in the onsubmit before email box is causing the problem. I was using some code you posted in another thread to get rid of the {field name}'s on my email.
Thanks,
Apryl
Thanks,
Apryl
Hi Apryl,
All fine now I think - there was a little misplaced text after one of the for (. . .) { dwtm lines. That broke the code completely but no error showed because of the redirect. If you turn Form Debug on then you will see any PHP Error messages.
Took me a long time to find as some of my debug coded added more errors :-(
Bob
PS I notice that you are running PHP 4 - some parts of ChronoForms will no longer run correctly on PHP4 or may give warning messages.
'
All fine now I think - there was a little misplaced text after one of the for (. . .) { dwtm lines. That broke the code completely but no error showed because of the redirect. If you turn Form Debug on then you will see any PHP Error messages.
Took me a long time to find as some of my debug coded added more errors :-(
Bob
PS I notice that you are running PHP 4 - some parts of ChronoForms will no longer run correctly on PHP4 or may give warning messages.
'
Thank you for finding that. I would have been looking for hours. That seemed to do the trick. I found out that if you add xml to the end of showcart (index.php?option=com_caddy&action=showcartxml) you can see if there are ghost items in the cart (as was the case of the qty 0 items). They are no longer there.
But now when I click the paypal button I get an internal server error. Could that be because of a debug setting?
Apryl
p.s. Your right, I need to update to PHP 5
But now when I click the paypal button I get an internal server error. Could that be because of a debug setting?
Apryl
p.s. Your right, I need to update to PHP 5
Hi Apryl,
I don't think that is anything to do with ChronoForms. If I just add the Volunteer optout and try to order I get the error :-(
Check the server logs and see if anything shows up there?
Bob
I don't think that is anything to do with ChronoForms. If I just add the Volunteer optout and try to order I get the error :-(
Check the server logs and see if anything shows up there?
Bob
Your right, it doesn't seem to be a problem with the forms. Probably too many requests in a short amount of time. I will look at it again with fresh eyes once I get a couple hours sleep. Thank you again for all of your help. I am thrilled that I am getting close to completing this project.
Apryl
Update: I had inadvertently activated a required checkout field in the cart that was not published. All is well now!😶
Apryl
Update: I had inadvertently activated a required checkout field in the cart that was not published. All is well now!😶
This topic is locked and no more replies can be posted.