4 * Class CRM_Event_Cart_Page_AddToCart
6 class CRM_Event_Cart_Page_AddToCart
extends CRM_Core_Page
{
8 use CRM_Core_Page_EntityPageTrait
;
11 * This function takes care of all the things common to all pages.
13 * This typically involves assigning the appropriate smarty variables :)
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'));
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'));
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();
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
,
35 CRM_Utils_System
::redirect($_SERVER['HTTP_REFERER']);