public function handle()
 {
     require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php';
     $ms = new \Components\Storefront\Models\Memberships();
     /* 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 dirname(dirname(dirname(__DIR__))) . DS . 'models' . DS . 'Cart.php';
         $userId = \Components\Cart\Models\Cart::getCartUser($this->crtId);
         // Get the 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 = \Components\Storefront\Models\Product::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 PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php';
     $ms = new \Components\Storefront\Models\Memberships();
     // 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 dirname(dirname(dirname(__DIR__))) . DS . 'models' . DS . 'Cart.php';
     $userId = \Components\Cart\Models\Cart::getCartUser($this->crtId);
     // Load courses model and register
     // registerForCourse($userId, $courseId, $expiration);
     require_once PATH_CORE . 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);
     }
 }
 public function handle()
 {
     $itemInfo = $this->item['info'];
     // Get user
     require_once dirname(dirname(dirname(__DIR__))) . DS . 'models' . DS . 'Cart.php';
     $uId = \Components\Cart\Models\Cart::getCartUser($this->crtId);
     // Get product type
     require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
     $warehouse = new \Components\Storefront\Models\Warehouse();
     $pType = $warehouse->getProductTypeInfo($itemInfo->ptId);
     $type = $pType['ptName'];
     require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php';
     $subscription = \Components\Storefront\Models\Memberships::getSubscriptionObject($type, $itemInfo->pId, $uId);
     // Get the expiration for the current subscription (if any)
     $currentExpiration = $subscription->getExpiration();
     // Calculate new expiration
     $newExpires = Components\Storefront\Models\Memberships::calculateNewExpiration($currentExpiration, $this->item);
     // Update/Create membership expiration date with new value
     $subscription->setExpiration($newExpires);
 }
Example #4
0
 /**
  * Handle memberships
  *
  * @param 	object 		$cartInfo
  * @param	object		$cartCoupons
  * @return 	object		membership info
  */
 public function getMembershipInfo()
 {
     $cartInfo = $this->getCartInfo();
     $cartItems = $cartInfo->items;
     // init membership info
     $memberships = array();
     require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php';
     $ms = new \Components\Storefront\Models\Memberships();
     // Get membership types
     $membershipTypes = $ms->getMembershipTypes();
     // Go through each product and see if the type is membership
     foreach ($cartItems as $sId => $item) {
         if (in_array($item['info']->ptId, $membershipTypes) && !empty($item['meta']['ttl'])) {
             $itemInfo = $item['info'];
             // Get product type
             $warehouse = $this->warehouse;
             $pType = $warehouse->getProductTypeInfo($itemInfo->ptId);
             $type = $pType['ptName'];
             // Get user
             $jUser = User::getInstance();
             // Get the correct membership Object
             $subscription = \Components\Storefront\Models\Memberships::getSubscriptionObject($type, $itemInfo->pId, $jUser->id);
             // Get the expiration for the current subscription (if any)
             $currentExpiration = $subscription->getExpiration();
             // Calculate new expiration
             $newExpires = \Components\Storefront\Models\Memberships::calculateNewExpiration($currentExpiration, $item);
             $membershipSIdInfo = new \stdClass();
             $membershipSIdInfo->newExpires = strtotime($newExpires);
             if ($currentExpiration && $currentExpiration['crtmActive']) {
                 $membershipSIdInfo->existingExpires = strtotime($currentExpiration['crtmExpires']);
             }
             $memberships[$sId] = $membershipSIdInfo;
             unset($membershipSIdInfo);
         }
     }
     return $memberships;
 }