4 * Class CRM_Event_Cart_Page_CheckoutAJAX
6 class CRM_Event_Cart_Page_CheckoutAJAX
{
7 public function add_participant_to_cart() {
8 $transaction = new CRM_Core_Transaction();
9 $cart_id = CRM_Utils_Request
::retrieve('cart_id', 'Integer');
10 $event_id = CRM_Utils_Request
::retrieve('event_id', 'Integer');
12 $cart = CRM_Event_Cart_BAO_Cart
::find_by_id($cart_id);
14 $params_array = array(
15 'cart_id' => $cart->id
,
16 'contact_id' => CRM_Event_Cart_Form_Cart
::find_or_create_contact(),
17 'event_id' => $event_id,
21 $participant = CRM_Event_Cart_BAO_MerParticipant
::create($params_array);
24 $form = new CRM_Core_Form();
25 $pform = new CRM_Event_Cart_Form_MerParticipant($participant);
26 $pform->appendQuickForm($form);
28 $renderer = $form->getRenderer();
30 $config = CRM_Core_Config
::singleton();
31 $templateDir = $config->templateDir
;
32 if (is_array($templateDir)) {
33 $templateDir = array_pop($templateDir);
35 $requiredTemplate = file_get_contents($templateDir . '/CRM/Form/label.tpl');
36 $renderer->setRequiredTemplate($requiredTemplate);
38 $form->accept($renderer);
39 $template = CRM_Core_Smarty
::singleton();
40 $template->assign('form', $renderer->toArray());
41 $template->assign('participant', $participant);
42 $output = $template->fetch("CRM/Event/Cart/Form/Checkout/Participant.tpl");
43 $transaction->commit();
45 CRM_Utils_System
::civiExit();
48 public function remove_participant_from_cart() {
49 $id = CRM_Utils_Request
::retrieve('id', 'Integer');
50 $participant = CRM_Event_Cart_BAO_MerParticipant
::get_by_id($id);
51 $participant->delete();
53 CRM_Utils_System
::civiExit();