Merge pull request #15785 from eileenmcnaughton/contribution_url_params
[civicrm-core.git] / CRM / Event / Cart / Page / AddToCart.php
1 <?php
2
3 /**
4 * Class CRM_Event_Cart_Page_AddToCart
5 */
6 class CRM_Event_Cart_Page_AddToCart extends CRM_Core_Page {
7
8 /**
9 * This function takes care of all the things common to all pages.
10 *
11 * This typically involves assigning the appropriate smarty variables :)
12 */
13 public function run() {
14 $transaction = new CRM_Core_Transaction();
15
16 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
17 if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id, 'register for events')) {
18 CRM_Core_Error::statusBounce(ts('You do not have permission to register for this event'));
19 }
20
21 $cart = CRM_Event_Cart_BAO_Cart::find_or_create_for_current_session();
22 $event_in_cart = $cart->add_event($this->_id);
23
24 $url = CRM_Utils_System::url('civicrm/event/view_cart');
25 CRM_Utils_System::setUFMessage(ts("<b>%1</b> has been added to your cart. <a href='%2'>View your cart.</a>", [
26 1 => $event_in_cart->event->title,
27 2 => $url,
28 ]));
29
30 $transaction->commit();
31
32 return CRM_Utils_System::redirect($_SERVER['HTTP_REFERER']);
33 }
34
35 }