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);
     }
 }
 public function handle()
 {
     // 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);
     // Get number of points to add
     if (!empty($this->item['meta']['addPoints']) && is_numeric($this->item['meta']['addPoints'])) {
         // Update points account
         $db = App::get('db');
         $BTL = new \Hubzero\Bank\Teller($db, $userId);
         $BTL->deposit($this->item['meta']['addPoints'], 'PRO Membership Bonus', 'PRO', $this->item['info']->sId);
     }
 }
 public function __construct($type, $pId = NULL, $crtId = NULL)
 {
     $this->type = $type;
     $this->pId = $pId;
     $this->crtId = $crtId;
     // Get user, if any
     $this->uId = CartModelCart::getCartUser($crtId);
     // Set up the default empty ok
     $this->response = new stdClass();
     $this->response->status = 'ok';
     $this->response->messages = array();
     $this->response->notices = array();
     $this->response->errors = array();
 }
 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);
 }
 public function emailOrderComplete($transactionInfo)
 {
     $params = Component::params(Request::getVar('option'));
     $items = unserialize($transactionInfo->tiItems);
     $meta = unserialize($transactionInfo->tiMeta);
     //print_r($items); die;
     // Build emails
     // Build order summary
     $summary = 'Order summary:';
     $summary .= "\n====================\n\n";
     $summary .= 'Order number: ' . $transactionInfo->tId . "\n\n";
     $summary .= 'Order subtotal: ' . money_format('%n', $transactionInfo->tiSubtotal) . "\n";
     if (!$transactionInfo->tiShipping) {
         $transactionInfo->tiShipping = 0;
     }
     if ($transactionInfo->tiShipping > 0) {
         $summary .= 'Shipping and handling: ' . money_format('%n', $transactionInfo->tiShipping) . "\n";
     }
     if (!$transactionInfo->tiTax) {
         $transactionInfo->tiTax = 0;
     }
     if ($transactionInfo->tiDiscounts > 0 || $transactionInfo->tiShippingDiscount > 0) {
         $summary .= 'Discounts: ' . money_format('%n', $transactionInfo->tiDiscounts + $transactionInfo->tiShippingDiscount) . "\n";
     }
     if ($transactionInfo->tiTax > 0) {
         $summary .= 'Tax: ' . money_format('%n', $transactionInfo->tiTax) . "\n";
     }
     $summary .= 'Order total: ' . money_format('%n', $transactionInfo->tiTotal) . "\n";
     if (!empty($transactionInfo->tiShippingToFirst)) {
         $summary .= "\n\nShipping address:";
         $summary .= "\n--------------------\n";
         $summary .= $transactionInfo->tiShippingToFirst . ' ' . $transactionInfo->tiShippingToLast . "\n";
         $summary .= $transactionInfo->tiShippingAddress . "\n";
         $summary .= $transactionInfo->tiShippingCity . ', ' . $transactionInfo->tiShippingState . ' ' . $transactionInfo->tiShippingZip . "\n";
     }
     $summary .= "\n\nItems ordered:";
     $summary .= "\n--------------------\n";
     foreach ($items as $k => $item) {
         $itemInfo = $item['info'];
         $cartInfo = $item['cartInfo'];
         // If course, generate a link to the course
         $action = false;
         if ($itemInfo->ptId == 20) {
             $action = ' Go to the course page at: ' . ($action .= Route::url('index.php?option=com_courses/' . $item['meta']['courseId'] . '/' . $item['meta']['offeringId'], true, -1));
         }
         $summary .= "{$cartInfo->qty} x ";
         $summary .= "{$itemInfo->pName}";
         if (!empty($item['options'])) {
             $summary .= '(';
             $optionCount = 0;
             foreach ($item['options'] as $option) {
                 if ($optionCount) {
                     $summary .= ', ';
                 }
                 $summary .= $option;
                 $optionCount++;
             }
             $summary .= ')';
         }
         $summary .= ' @ ' . money_format('%n', $itemInfo->sPrice);
         if ($action) {
             $summary .= "\n\t";
             $summary .= $action;
         }
         $summary .= "\n";
     }
     //print_r($summary); die;
     // "from" info
     $from = array();
     $from['name'] = Config::get('sitename');
     $from['email'] = Config::get('mailfrom');
     // Email to admin
     $adminEmail = "There is a new online store order: \n\n";
     $adminEmail .= $summary;
     // Admin email
     $to = array($params->get('storeAdminId'));
     Event::trigger('xmessage.onSendMessage', array('store_notifications', 'New order at ' . $from['name'], $adminEmail, $from, $to, '', null, '', 0, true));
     // Email to client
     $clientEmail = 'Thank you for your order at ' . Config::get('sitename') . "!\n\n";
     $clientEmail .= $summary;
     require_once PATH_CORE . DS . 'components' . DS . 'com_cart' . DS . 'models' . DS . 'Cart.php';
     $to = array(CartModelCart::getCartUser($transactionInfo->crtId));
     Event::trigger('xmessage.onSendMessage', array('store_notifications', 'Your order at ' . $from['name'], $clientEmail, $from, $to, '', null, '', 0, true));
 }