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;
     }
 }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
 /**
  * Main handler. Does all the checks
  *
  * @param 	void
  * @return 	void
  */
 public function audit()
 {
     /* Membership may have a limit on when it can be extended */
     /* If no user, some checks may be skipped... */
     // Get user
     if (!User::isGuest()) {
         // Check if there is a limitation on when the subscription can be extended
         require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Product.php';
         $subscriptionMaxLen = StorefrontModelProduct::getMeta($this->pId, 'subscriptionMaxLen');
         if ($subscriptionMaxLen) {
             /* Check if the current user has the existing subscription and how much is left on it
             		 i.e. figure out if he may extend his current subscription */
             /*
              *  This is not working very well for multiple SKUs with multiple subscriptionMaxLen's
              *  at this point code doesn't know what SKU will be added,
              *  so for one SKU subscriptionMaxLen should
              *  be set to time less than actual membership length, ie if membership is sold for 1 year and
              *  cannot be renewed more than 6 month before it expires the subscriptionMaxLen must be set to 6 MONTH
              *  if it cannot be renewed more than 3 month before it expires the subscriptionMaxLen must be set to 3 MONTH
              *
              *  so subscriptionMaxLen = XX is actually "let renew XX time before expiration"
              */
             // Get the proper product type subscription object reference
             require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php';
             $subscription = StorefrontModelMemberships::getSubscriptionObject($this->type, $this->pId, $this->uId);
             // Get the expiration for the current subscription (if any)
             $currentExpiration = $subscription->getExpiration();
             if ($currentExpiration && $currentExpiration['crtmActive']) {
                 // Do the check
                 $currentExpirationTime = $currentExpiration['crtmExpires'];
                 // See if current expiration is later than max allowed time from now (max allowed time + now)
                 if (strtotime('+' . $subscriptionMaxLen) < strtotime($currentExpirationTime)) {
                     // Expiration is not allowed -- the current expiration is too far in the future
                     $this->setResponseStatus('error');
                     $this->setResponseNotice('You already have an active subscription to this item. Subscription extension is not available at this time.');
                     $this->setResponseError(': you already have an active subscription. Subscription extension is not available at this time.');
                 }
             }
         }
     }
     return $this->getResponse();
 }
 public function handle()
 {
     $itemInfo = $this->item['info'];
     // Get user
     require_once JPATH_BASE . DS . 'components' . DS . 'com_cart' . DS . 'models' . DS . 'Cart.php';
     $uId = CartModelCart::getCartUser($this->crtId);
     // Get product type
     require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
     $warehouse = new StorefrontModelWarehouse();
     $pType = $warehouse->getProductTypeInfo($itemInfo->ptId);
     $type = $pType['ptName'];
     require_once JPATH_BASE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php';
     $subscription = StorefrontModelMemberships::getSubscriptionObject($type, $itemInfo->pId, $uId);
     // Get the expiration for the current subscription (if any)
     $currentExpiration = $subscription->getExpiration();
     // Calculate new expiration
     $newExpires = StorefrontModelMemberships::calculateNewExpiration($currentExpiration, $this->item);
     // Update/Create membership expiration date with new value
     $subscription->setExpiration($newExpires);
 }
Exemplo n.º 5
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();
     include_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Memberships.php';
     $ms = new StorefrontModelMemberships();
     // 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
             require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
             $warehouse = new StorefrontModelWarehouse();
             $pType = $warehouse->getProductTypeInfo($itemInfo->ptId);
             $type = $pType['ptName'];
             // Get the correct membership Object
             $subscription = StorefrontModelMemberships::getSubscriptionObject($type, $itemInfo->pId, User::get('id'));
             // Get the expiration for the current subscription (if any)
             $currentExpiration = $subscription->getExpiration();
             // Calculate new expiration
             $newExpires = StorefrontModelMemberships::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;
 }
Exemplo n.º 6
0
 public function setTimeToLive($ttl)
 {
     StorefrontModelMemberships::checkTtl($ttl);
     $this->data->meta['ttl'] = $ttl;
 }