コード例 #1
0
 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()
 {
     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;
     }
 }
コード例 #3
0
 public function handle()
 {
     // 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 number of points to add
     if (!empty($this->item['meta']['addPoints']) && is_numeric($this->item['meta']['addPoints'])) {
         // Update points account
         $BTL = new \Hubzero\Bank\Teller($userId);
         $BTL->deposit($this->item['meta']['addPoints'], 'PRO Membership Bonus', 'PRO', $this->item['info']->sId);
     }
 }
コード例 #4
0
 public function __construct($type, $pId = NULL, $crtId = NULL)
 {
     $this->type = $type;
     $this->pId = $pId;
     $this->crtId = $crtId;
     // Get user, if any
     $this->uId = \Components\Cart\Models\Cart::getCartUser($crtId);
     // Set up the default empty ok response
     $this->response = new \stdClass();
     $this->response->status = 'ok';
     $this->response->messages = array();
     $this->response->notices = array();
     $this->response->errors = array();
 }
コード例 #5
0
 public function handle()
 {
     $itemInfo = $this->item['info'];
     $itemMeta = $this->item['meta'];
     $itemCartInfo = $this->item['cartInfo'];
     // Check the serial management. If multiple -- need to update the transaction info items with the serials and mark the serials as used
     if (isset($itemMeta['serialManagement']) && $itemMeta['serialManagement'] == 'multiple') {
         // Get the required number of serials
         $serialsNeeded = $itemCartInfo->qty;
         require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'helpers' . DS . 'Serials.php';
         // Get the serial numbers
         $serialNumbers = \Components\Storefront\Helpers\Serials::issueSerials($itemInfo->sId, $serialsNeeded);
         $this->item['meta']['serials'] = $serialNumbers;
         // Update the transaction items with serials
         require_once dirname(dirname(dirname(__DIR__))) . DS . 'models' . DS . 'Cart.php';
         \Components\Cart\Models\Cart::updateTransactionItem($this->tId, $this->item);
     }
 }
コード例 #6
0
 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);
 }
コード例 #7
0
ファイル: orders.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Display default page
  *
  * @return     void
  */
 public function homeTask()
 {
     // Incoming
     $this->view->filters = array('limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0));
     $cart = new CurrentCart();
     // Get all completed transactions count
     $this->view->total = $cart->getTransactions(array('count' => true));
     // Get all completed transactions
     $transactions = $cart->getTransactions($this->view->filters);
     // Get transactions' info
     if ($transactions) {
         foreach ($transactions as $transaction) {
             $transactionInfo = Cart::getTransactionInfo($transaction->tId);
             // Figure out if the items int the transactions are still avaialble
             $tItems = unserialize($transactionInfo->tiItems);
             foreach ($tItems as $item) {
                 // Check if the product is still available
                 $warehouse = new Warehouse();
                 $skuInfo = $warehouse->getSkuInfo($item['info']->sId, false);
                 $item['info']->available = true;
                 if (!$skuInfo) {
                     // product no longer available
                     $item['info']->available = false;
                 }
             }
             $transactionInfo->tiItems = $tItems;
             $transaction->tInfo = $transactionInfo;
         }
     }
     $this->view->transactions = $transactions;
     if (Pathway::count() <= 0) {
         Pathway::append(Lang::txt(strtoupper($this->_option)), 'index.php?option=' . $this->_option);
         Pathway::append(Lang::txt('COM_CART_ORDERS'), 'index.php?option=' . $this->_option);
     }
     //print_r($transactions); die;
     $this->view->display();
 }
コード例 #8
0
ファイル: CurrentCart.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Kill all cart pending transactions
  *
  * @param void
  * @return void
  */
 private function cleanOldTransactions()
 {
     if (empty($this->cart->crtId)) {
         return true;
     }
     // Get all pending transactions for this cart
     $sql = "SELECT `tId` FROM `#__cart_transactions` WHERE `crtId` = {$this->cart->crtId} AND `tStatus` = 'pending'";
     $this->_db->setQuery($sql);
     $tIds = $this->_db->loadColumn();
     if (is_array($tIds)) {
         foreach ($tIds as $tId) {
             $this->releaseTransaction($tId);
             parent::killTransaction($tId);
         }
     }
     $this->cart->tId = NULL;
 }
コード例 #9
0
 public function emailOrderComplete($transactionInfo)
 {
     $params = Component::params(Request::getVar('option'));
     $items = unserialize($transactionInfo->tiItems);
     //print_r($items); die;
     // Build emails
     // Build order summary
     $summary = 'Order number: ' . $transactionInfo->tId . "\n\n";
     $summary .= "\n====================\n\n";
     $summary .= 'Subtotal: ' . '$' . number_format($transactionInfo->tiSubtotal, 2) . "\n";
     if (!$transactionInfo->tiShipping) {
         $transactionInfo->tiShipping = 0;
     }
     if ($transactionInfo->tiShipping > 0) {
         $summary .= 'Shipping and handling: ' . '$' . number_format($transactionInfo->tiShipping, 2) . "\n";
     }
     if (!$transactionInfo->tiTax) {
         $transactionInfo->tiTax = 0;
     }
     if ($transactionInfo->tiDiscounts > 0 || $transactionInfo->tiShippingDiscount > 0) {
         $summary .= 'Discounts: ' . '$' . number_format($transactionInfo->tiDiscounts + $transactionInfo->tiShippingDiscount, 2) . "\n";
     }
     if ($transactionInfo->tiTax > 0) {
         $summary .= 'Tax: ' . '$' . number_format($transactionInfo->tiTax, 2) . "\n";
     }
     $summary .= 'Total: ' . '$' . number_format($transactionInfo->tiTotal, 2) . "\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";
     require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
     $warehouse = new \Components\Storefront\Models\Warehouse();
     foreach ($items as $k => $item) {
         $itemInfo = $item['info'];
         $cartInfo = $item['cartInfo'];
         $itemMeta = $item['meta'];
         //print_r($item); die;
         $productType = $warehouse->getProductTypeInfo($itemInfo->ptId)['ptName'];
         // If course, generate a link to the course
         $action = false;
         if ($productType == 'Course') {
             $action = ' Go to the course page at: ' . ($action .= Route::url('index.php?option=com_courses', true, -1) . $itemMeta['courseId'] . '/' . $itemMeta['offeringId']);
         } elseif ($productType == 'Software Download') {
             $action = ' Download at: ' . ($action .= Route::url('index.php?option=com_cart', true, -1) . 'download/' . $transactionInfo->tId . '/' . $itemInfo->sId);
             if (isset($itemMeta['serial']) && !empty($itemMeta['serial'])) {
                 $action .= "\n\t";
                 $action .= " Serial number: " . $itemMeta['serial'];
             }
         }
         $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 .= ' @ ' . '$' . number_format($itemInfo->sPrice, 2);
         if ($action) {
             $summary .= "\n\t";
             $summary .= $action;
         }
         $summary .= "\n";
     }
     //print_r($summary); die;
     // Get message plugin
     JPluginHelper::importPlugin('xmessage');
     // "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('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 dirname(dirname(__DIR__)) . DS . 'models' . DS . 'Cart.php';
     $to = array(\Components\Cart\Models\Cart::getCartUser($transactionInfo->crtId));
     Event::trigger('onSendMessage', array('store_notifications', 'Your order at ' . $from['name'], $clientEmail, $from, $to, '', null, '', 0, true));
     // Email notification extra
     $notifyTo = $params->get('sendNotificationTo');
     if (!empty($notifyTo)) {
         $notifyTo = explode(',', str_replace(' ', '', $notifyTo));
         $notifyEmail = 'There is a new online store order at ' . Config::get('sitename') . "\n\n";
         $notifyEmail .= $summary;
         // Plain text email
         $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'order_notify'));
         $eview->option = $this->_option;
         $eview->controller = $this->_controller;
         $eview->message = $notifyEmail;
         $plain = $eview->loadTemplate();
         $plain = str_replace("\n", "\r\n", $plain);
         $message = new \Hubzero\Mail\Message();
         $message->setSubject('ORDER NOTIFICATION: New order at ' . $from['name']);
         $message->addFrom(Config::get('mailfrom'), Config::get('sitename'));
         $message->addPart($plain, 'text/plain');
         foreach ($notifyTo as $email) {
             if (\Hubzero\Utility\Validate::email($email)) {
                 $message->addTo($email);
             }
         }
         $message->setBody($plain);
         $message->send();
     }
 }
コード例 #10
0
ファイル: orders.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Download CSV report (default)
  *
  * @return     void
  */
 public function downloadOrdersTask()
 {
     // Get filters
     $filters = array('sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'dDownloaded'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'));
     //print_r($filters); die;
     // Get orders, request array to be returned
     $orders = CartOrders::getItemsOrdered('list', $filters);
     foreach ($orders as $order) {
         $orderItems = unserialize(Cart::getTransactionInfo($order->tId)->tiItems);
         $order->itemInfo = $orderItems[$order->sId];
     }
     $rowsRaw = $orders;
     $date = date('d-m-Y');
     $rows = array();
     foreach ($rowsRaw as $row) {
         $itemInfo = $row->itemInfo['info'];
         $rows[] = array($row->sId, $itemInfo->pName . ', ' . $itemInfo->sSku, $row->tiQty, $row->tiPrice, $row->tId, $row->tLastUpdated, $row->Name, $row->uidNumber);
     }
     header("Content-Type: text/csv");
     header("Content-Disposition: attachment; filename=cart-items-ordered" . $date . ".csv");
     // Disable caching
     header("Cache-Control: no-cache, no-store, must-revalidate");
     // HTTP 1.1
     header("Pragma: no-cache");
     // HTTP 1.0
     header("Expires: 0");
     // Proxies
     $output = fopen("php://output", "w");
     $row = array('SKU ID', 'Product', 'QTY', 'Price', 'Order ID', 'Order Placed', 'Purchased By', 'Purchased By (userId)');
     fputcsv($output, $row);
     foreach ($rows as $row) {
         fputcsv($output, $row);
     }
     fclose($output);
     die;
 }
コード例 #11
0
ファイル: order.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Complete transaction
  *
  * @return     void
  */
 private function completeOrder($tInfo)
 {
     // Handle transaction according to items handlers
     Cart::completeTransaction($tInfo);
     // Initialize logger
     $logger = new \CartMessenger('Complete order');
     // Send emails to customer and admin
     $logger->emailOrderComplete($tInfo->info);
     return true;
 }
コード例 #12
0
ファイル: checkout.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Confirm step of the checkout. Should be a pass-through page for JS-enabled browsers, requires a form submission to the payment gateway
  *
  * @return     void
  */
 public function confirmTask()
 {
     $cart = new CurrentCart();
     $transaction = $cart->liftTransaction();
     if (!$transaction) {
         $cart->redirect('home');
     }
     // Get security token
     $transaction->token = $cart->getToken();
     // Check if there are any steps missing. Redirect if needed
     $nextStep = $cart->getNextCheckoutStep()->step;
     if ($nextStep != 'summary') {
         $cart->redirect($nextStep);
     }
     // Final step here before payment
     Cart::updateTransactionStatus('awaiting payment', $transaction->info->tId);
     // Generate payment code
     $params = Component::params(Request::getVar('option'));
     $paymentGatewayProivder = $params->get('paymentProvider');
     require_once dirname(dirname(__DIR__)) . DS . 'lib' . DS . 'payment' . DS . 'PaymentDispatcher.php';
     $paymentDispatcher = new \PaymentDispatcher($paymentGatewayProivder);
     $pay = $paymentDispatcher->getPaymentProvider();
     $pay->setTransactionDetails($transaction);
     $error = false;
     try {
         $paymentCode = $pay->getPaymentCode();
         $this->view->paymentCode = $paymentCode;
     } catch (\Exception $e) {
         $error = $e->getMessage();
     }
     if (!empty($error)) {
         $this->view->setError($error);
     }
     $this->view->display();
 }
コード例 #13
0
ファイル: download.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Serve the file
  *
  * @param		$pId
  * @return     	void
  */
 public function displayTask()
 {
     // Get the transaction ID
     $tId = Request::getInt('task', '');
     // Get the SKU ID
     $sId = Request::getVar('p0');
     // Get the landing page flag
     $direct = Request::getVar('p1');
     // Check if the transaction is complete and belongs to the user and is active and the SKU requested is valid
     $transaction = Cart::getTransactionFacts($tId);
     $transactionExistingItems = $transaction->items;
     $transaction = $transaction->info;
     $transactionItems = unserialize($transaction->tiItems);
     $tStatus = $transaction->tStatus;
     $crtId = $transaction->crtId;
     // get cart user
     $cartUser = Cart::getCartUser($crtId);
     $currentUser = $this->juser->id;
     // Error if needed
     if ($tStatus !== 'completed') {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_TRANSACTION_NOT_COMPLETED'), 'error'));
         $this->messageTask($messages);
         return;
     } elseif ($cartUser != $currentUser) {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_NOT_AUTHORIZED'), 'error'));
         $this->messageTask($messages);
         return;
     } elseif (!array_key_exists($sId, $transactionItems)) {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_NOT_AUTHORIZED'), 'error'));
         $this->messageTask($messages);
         return;
     }
     // Check if the product is valid and downloadable; find the file
     $warehouse = new Warehouse();
     $sku = $warehouse->getSkuInfo($sId);
     $productType = $warehouse->getProductTypeInfo($sku['info']->ptId);
     $downloadFile = $sku['meta']['downloadFile'];
     // Error if needed
     if ($productType['ptName'] != 'Software Download' || empty($downloadFile)) {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_FILE_NOT_DOWNLOADABLE'), 'error'));
         $this->messageTask($messages);
         return;
     }
     $db = \App::get('db');
     // Check if there is a limit on how many times the product can be downloaded
     // Get the number of downloads allowed
     if (isset($sku['meta']['downloadLimit']) && $sku['meta']['downloadLimit'] && is_numeric($sku['meta']['downloadLimit'])) {
         $sql = "SELECT COUNT(`dId`) FROM `#__cart_downloads` WHERE `uId` = {$currentUser} AND `sId` = {$sId} AND `dStatus` > 0";
         $db->setQuery($sql);
         $downloadsCount = $db->loadResult();
         if ($downloadsCount >= $sku['meta']['downloadLimit']) {
             $messages = array(array('Download limit exceeded', 'error'));
             $this->messageTask($messages);
             return;
         }
     }
     // Path and file name
     $storefrontConfig = Component::params('com_storefront');
     $dir = $storefrontConfig->get('downloadFolder', '/site/protected/storefront/software');
     $file = PATH_APP . $dir . DS . $downloadFile;
     if (!file_exists($file)) {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_FILE_NOT_FOUND'), 'error'));
         $this->messageTask($messages);
         return;
     }
     if (!$direct) {
         $this->landingTask($tId, $sId);
         return;
     }
     // Log the download
     $sql = "INSERT INTO `#__cart_downloads` SET\n\t\t\t\t`uId` = " . $currentUser . ",\n\t\t\t\t`sId` = " . $sId . ",\n\t\t\t\t`dIp` = INET_ATON(" . $db->quote(Request::ip()) . "),\n\t\t\t\t`dDownloaded` = NOW()";
     $db->setQuery($sql);
     $db->query();
     $dId = $db->insertid();
     // Save the meta data
     $userGroups = User::getAuthorisedGroups();
     $meta = array();
     $ignoreGroups = array('public', 'registered');
     foreach ($userGroups as $groupId) {
         $group = Accessgroup::one($groupId);
         if (!in_array(strtolower($group->get('title')), $ignoreGroups)) {
             $meta[$groupId] = $group->get('title');
         }
     }
     if ($mta = User::getState('metadata')) {
         $meta = array_merge($meta, $mta);
     }
     $sql = "INSERT INTO `#__cart_meta` SET\n\t\t\t\t`scope_id` = " . $dId . ",\n\t\t\t\t`scope` = 'download',\n\t\t\t\t`mtKey` = 'userInfo',\n\t\t\t\t`mtValue` = '" . serialize($meta) . "'";
     $db->setQuery($sql);
     $db->query();
     // Figure out if the EULA was accepted
     $itemTransactionInfoMeta = $transactionExistingItems[$sId]['transactionInfo']->tiMeta;
     $eulaAccepted = $itemTransactionInfoMeta && property_exists($itemTransactionInfoMeta, 'eulaAccepted') && $itemTransactionInfoMeta->eulaAccepted ? true : false;
     if ($eulaAccepted) {
         $sql = "INSERT INTO `#__cart_meta` SET\n\t\t\t\t\t`scope_id` = " . $dId . ",\n\t\t\t\t\t`scope` = 'download',\n\t\t\t\t\t`mtKey` = 'eulaAccepted',\n\t\t\t\t\t`mtValue` = '" . $eulaAccepted . "'";
         $db->setQuery($sql);
         $db->query();
     }
     // Serve up the file
     $xserver = new \Hubzero\Content\Server();
     $xserver->filename($file);
     $xserver->serve_attachment($file);
     // Firefox and Chrome fail if served inline
     exit;
 }
コード例 #14
0
ファイル: download.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Serve the file
  *
  * @param		$pId
  * @return     	void
  */
 public function displayTask()
 {
     // Get the transaction ID
     $tId = Request::getInt('task', '');
     // Get the SKU ID
     $sId = Request::getVar('p0');
     // Get the landing page flag
     $direct = Request::getVar('p1');
     // Check if the transaction is complete and belongs to the user and is active
     $transaction = Cart::getTransactionFacts($tId);
     $transaction = $transaction->info;
     $tStatus = $transaction->tStatus;
     $crtId = $transaction->crtId;
     // get cart user
     $cartUser = Cart::getCartUser($crtId);
     $currentUser = $this->juser->id;
     // Error if needed
     if ($tStatus !== 'completed') {
         $messages = array(array('COM_CART_DOWNLOAD_TRANSACTION_NOT_COMPLETED', 'error'));
         $this->messageTask($messages);
         return;
     } elseif ($cartUser != $currentUser) {
         $messages = array(array('COM_CART_DOWNLOAD_NOT_AUTHORIZED', 'error'));
         $this->messageTask($messages);
         return;
     }
     // Check if the product is valid and downloadable; find the file
     $warehouse = new Warehouse();
     $sku = $warehouse->getSkuInfo($sId);
     $productType = $sku['info']->ptId;
     $downloadFile = $sku['meta']['downloadFile'];
     // Error if needed
     if ($productType != 30 || empty($downloadFile)) {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_FILE_NOT_DOWNLOABLE'), 'error'));
         $this->messageTask($messages);
         return;
     }
     $db = \App::get('db');
     // Check if there is a limit on how many times the product can be downloaded
     // Get the number of downloads allowed
     $allowedDownloads = $sku;
     if (isset($sku['meta']['downloadLimit']) && $sku['meta']['downloadLimit'] && is_numeric($sku['meta']['downloadLimit'])) {
         $sql = "SELECT COUNT(`dId`) FROM `#__cart_downloads` WHERE `uId` = {$currentUser} AND `sId` = {$sId}";
         $db->setQuery($sql);
         $downloadsCount = $db->loadResult();
         if ($downloadsCount >= $sku['meta']['downloadLimit']) {
             $messages = array(array('Download limit exceeded', 'error'));
             $this->messageTask($messages);
             return;
         }
     }
     // Path and file name
     $storefrontConfig = Component::params('com_storefront');
     $dir = $storefrontConfig->get('downloadFolder');
     $file = PATH_ROOT . $dir . DS . $downloadFile;
     if (!file_exists($file)) {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_FILE_NOT_FOUND'), 'error'));
         $this->messageTask($messages);
         return;
     }
     if (!$direct) {
         $this->landingTask($tId, $sId);
         return;
     }
     // Log the download
     $sql = "INSERT INTO `#__cart_downloads` SET\n\t\t\t\t`uId` = " . $currentUser . ",\n\t\t\t\t`sId` = " . $sId . ",\n\t\t\t\t`dIp` = INET_ATON(" . $db->quote(Request::getClientIp()) . "),\n\t\t\t\t`dDownloaded` = NOW()";
     $db->setQuery($sql);
     $db->query();
     // Serve up the file
     $xserver = new \Hubzero\Content\Server();
     $xserver->filename($file);
     $xserver->serve_attachment($file);
     // Firefox and Chrome fail if served inline
     exit;
 }