Merge pull request #11372 from ejegg/apiFixAddress
[civicrm-core.git] / CRM / Event / Cart / Page / CheckoutAJAX.php
CommitLineData
6a488035 1<?php
0cf587a7
EM
2
3/**
4 * Class CRM_Event_Cart_Page_CheckoutAJAX
5 */
6a488035 6class CRM_Event_Cart_Page_CheckoutAJAX {
00be9182 7 public function add_participant_to_cart() {
6a488035 8 $transaction = new CRM_Core_Transaction();
c31109f1
EM
9 $cart_id = CRM_Utils_Request::retrieve('cart_id', 'Integer');
10 $event_id = CRM_Utils_Request::retrieve('event_id', 'Integer');
6a488035 11
c31109f1 12 $cart = CRM_Event_Cart_BAO_Cart::find_by_id($cart_id);
6a488035 13
353ffa53
TO
14 $params_array = array(
15 'cart_id' => $cart->id,
16 'contact_id' => CRM_Event_Cart_Form_Cart::find_or_create_contact(),
7c550ca0 17 'event_id' => $event_id,
353ffa53 18 );
37b5eb89
A
19
20 //XXX security?
21 $participant = CRM_Event_Cart_BAO_MerParticipant::create($params_array);
6a488035
TO
22 $participant->save();
23
24 $form = new CRM_Core_Form();
25 $pform = new CRM_Event_Cart_Form_MerParticipant($participant);
26 $pform->appendQuickForm($form);
27
28 $renderer = $form->getRenderer();
29
30 $config = CRM_Core_Config::singleton();
31 $templateDir = $config->templateDir;
32 if (is_array($templateDir)) {
33 $templateDir = array_pop($templateDir);
34 }
35 $requiredTemplate = file_get_contents($templateDir . '/CRM/Form/label.tpl');
36 $renderer->setRequiredTemplate($requiredTemplate);
37
6a488035 38 $template = CRM_Core_Smarty::singleton();
ded1aa6e 39 $template->assign('form', $form->toSmarty());
6a488035
TO
40 $template->assign('participant', $participant);
41 $output = $template->fetch("CRM/Event/Cart/Form/Checkout/Participant.tpl");
42 $transaction->commit();
43 echo $output;
44 CRM_Utils_System::civiExit();
45 }
46
00be9182 47 public function remove_participant_from_cart() {
c31109f1
EM
48 $id = CRM_Utils_Request::retrieve('id', 'Integer');
49 $participant = CRM_Event_Cart_BAO_MerParticipant::get_by_id($id);
6a488035
TO
50 $participant->delete();
51
52 CRM_Utils_System::civiExit();
53 }
96025800 54
6a488035 55}