public function handle() { include_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php'; $ms = new StorefrontModelMemberships(); /* NEW $subscription = StorefrontModelMemberships::getSubscriptionObject($this->type, $this->pId, $this->uId); // Get the expiration for the current subscription (if any) $currentExpiration = $subscription->getExpiration(); */ // Get current registration $membership = $ms->getMembershipInfo($this->crtId, $this->item['info']->pId); $expiration = $membership['crtmExpires']; /* Add the user to the corresponding user access group (pull access group ID from the meta) */ try { // Get user ID for the cart require_once PATH_CORE . DS . 'components' . DS . 'com_cart' . DS . 'models' . DS . 'Cart.php'; $userId = CartModelCart::getCartUser($this->crtId); // Get user group ID to set the user to (from meta) require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Product.php'; $userGId = StorefrontModelProduct::getMeta($this->item['info']->pId, 'userGroupId'); $add = JUserHelper::addUserToGroup($userId, $userGId); if ($add instanceof Exception) { mail(Config::get('mailfrom'), 'Error adding to the group', $add->getMessage() . ' Cart #' . $this->crtId); } $table = JTable::getInstance('User', 'JTable', array()); $table->load($userId); // Trigger the onAftereStoreUser event Event::trigger('onUserAfterSave', array($table->getProperties(), false, true, null)); } catch (Exception $e) { // Error return false; } }
public function handle() { require_once JPATH_BASE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php'; $ms = new StorefrontModelMemberships(); // Get current registration $membership = $ms->getMembershipInfo($this->crtId, $this->item['info']->pId); $expiration = $membership['crtmExpires']; // Get course ID $courseId = $this->item['meta']['courseId']; // Get user ID for the cart require_once JPATH_BASE . DS . 'components' . DS . 'com_cart' . DS . 'models' . DS . 'Cart.php'; $userId = CartModelCart::getCartUser($this->crtId); // Load courses model and register // registerForCourse($userId, $courseId, $expiration); require_once JPATH_BASE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'course.php'; $course = \Components\Courses\Models\Course::getInstance($this->item['meta']['courseId']); if (!$course->offerings()->count()) { // error enrolling } else { // Get to the first and probably the only offering //$offering = $course->offerings()->current(); $offering = $course->offering($this->item['meta']['offeringId']); $offering->add($userId); //$offering->remove($userId); } }