Merge pull request #16671 from eileenmcnaughton/acl
[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 use CRM_Core_Page_EntityPageTrait;
9
10 /**
11 * This function takes care of all the things common to all pages.
12 *
13 * This typically involves assigning the appropriate smarty variables :)
14 */
15 public function run() {
16 $this->_id = CRM_Utils_Request::retrieveValue('id', 'Positive', NULL);
17 if (empty($this->_id)) {
18 CRM_Core_Error::statusBounce(ts('Missing required parameters'), NULL, ts('Add to cart'));
19 }
20 if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id, 'register for events')) {
21 CRM_Core_Error::statusBounce(ts('You do not have permission to register for this event'));
22 }
23
24 $transaction = new CRM_Core_Transaction();
25 $cart = CRM_Event_Cart_BAO_Cart::find_or_create_for_current_session();
26 $event_in_cart = $cart->add_event($this->_id);
27 $transaction->commit();
28
29 $cartUrl = CRM_Utils_System::url('civicrm/event/view_cart');
30 CRM_Utils_System::setUFMessage(ts("<b>%1</b> has been added to your <a href='%2'>cart</a>.", [
31 1 => $event_in_cart->event->title,
32 2 => $cartUrl,
33 ]));
34
35 CRM_Utils_System::redirect($_SERVER['HTTP_REFERER']);
36 }
37
38 }