Beispiel #1
0
 /**
  * Display a list of all downloads
  *
  * @return  void
  */
 public function displayTask()
 {
     // Get filters
     $this->view->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'), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'), 'skuRequested' => Request::getState($this->_option . '.' . $this->_controller . '.skuRequested', 'skuRequested', 0));
     // Is a particular SKU requested?
     $skuRequested = Request::getInt('sku', 0);
     if (!$skuRequested && !empty($this->view->filters['skuRequested'])) {
         $skuRequested = $this->view->filters['skuRequested'];
     }
     if ($skuRequested) {
         $warehouse = new Warehouse();
         $skuInfo = $warehouse->getSkuInfo($skuRequested);
         if ($skuInfo) {
             $skuName = $skuInfo['info']->pName . ', ' . $skuInfo['info']->sSku;
         } else {
             $skuName = 'Product no longer exists';
         }
         $this->view->filters['skuRequested'] = $skuRequested;
         $this->view->skuRequestedName = $skuName;
     }
     //print_r($this->view->filters); die;
     // Clean filters -- reset to default if needed
     $allowedSorting = array('product', 'dName', 'dDownloaded', 'dStatus');
     if (!in_array($this->view->filters['sort'], $allowedSorting)) {
         $this->view->filters['sort'] = 'dDownloaded';
     }
     // Get record count
     $this->view->total = CartDownload::getDownloads('count', $this->view->filters);
     // Get records
     $this->view->rows = CartDownload::getDownloads('list', $this->view->filters);
     //print_r($this->view->rows); die;
     // Output the HTML
     $this->view->display();
 }
Beispiel #2
0
 /**
  * Display a list of all categories
  *
  * @return  void
  */
 public function displayTask()
 {
     // Get filters
     $this->view->filters = array('sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'title'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'));
     $obj = new Archive();
     // Get record count
     $this->view->total = $obj->products('count', $this->view->filters);
     // Get records
     $this->view->rows = $obj->products('list', $this->view->filters);
     // For all records here get SKUs
     $skus = new \stdClass();
     $warehouse = new Warehouse();
     foreach ($this->view->rows as $r) {
         $key = $r->pId;
         $allSkus = $warehouse->getProductSkus($r->pId, 'all', false);
         // Count how many active and how many inactive SKUs there are
         $skuCounter = new \stdClass();
         $skuCounter->active = 0;
         $skuCounter->inactive = 0;
         foreach ($allSkus as $skuInfo) {
             if ($skuInfo->sActive) {
                 $skuCounter->active++;
             } else {
                 $skuCounter->inactive++;
             }
         }
         $skus->{$key} = $skuCounter;
     }
     $this->view->skus = $skus;
     // access groups
     $accessGroups = array();
     if ($this->config->get('productAccess')) {
         $ag = \Hubzero\Access\Group::all()->rows();
         $accessGroups[0] = 'None';
         foreach ($ag as $obj) {
             $accessGroups[$obj->get('id')] = $obj->get('title');
         }
     } else {
         $ag = Access::assetgroups();
         $accessGroups[0] = 'All';
         foreach ($ag as $obj) {
             $accessGroups[$obj->value] = $obj->text;
         }
     }
     $this->view->ag = $accessGroups;
     // Output the HTML
     $this->view->set('config', $this->config)->display();
 }
 /**
  * Process item
  *
  * @param 	void
  * @return 	bool
  */
 public function handle()
 {
     // Get product type info
     $ptId = $this->item['info']->ptId;
     $warehouse = new Warehouse();
     $ptIdTypeInfo = $warehouse->getProductTypeInfo($ptId);
     // Run both product model handler and type handler if needed.
     // Model handlers must go first for type handlers to potentially use their updates
     $handlersPath = PATH_CORE . DS . 'components' . DS . 'com_cart' . DS . 'lib' . DS . 'handlers';
     // MODEL HANDLER
     $modelHandlerClass = str_replace(' ', '_', ucwords(strtolower($ptIdTypeInfo['ptModel']))) . '_Model_Handler';
     if (file_exists($handlersPath . DS . 'model' . DS . $modelHandlerClass . '.php')) {
         // Include the parent class
         include_once $handlersPath . DS . 'ModelHandler.php';
         // Include the handler file
         include_once $handlersPath . DS . 'model' . DS . $modelHandlerClass . '.php';
         $modelHandler = new $modelHandlerClass($this->item, $this->crtId, $this->tId);
         $modelHandler->handle();
     }
     // TYPE HANDLER
     $typeHandlerClass = str_replace(' ', '_', ucwords(strtolower($ptIdTypeInfo['ptName']))) . '_Type_Handler';
     //print_r($typeHandlerClass); die;
     if (file_exists($handlersPath . DS . 'type' . DS . $typeHandlerClass . '.php')) {
         // Include the parent class
         include_once $handlersPath . DS . 'TypeHandler.php';
         // Include the handler file
         include_once $handlersPath . DS . 'type' . DS . $typeHandlerClass . '.php';
         $typeHandler = new $typeHandlerClass($this->item, $this->crtId);
         $typeHandler->handle();
     }
     // CUSTOM HANDLERS (if any)
     if (!empty($this->item['meta']['customHandler'])) {
         $customHandler = $this->item['meta']['customHandler'];
         $customHandlerClass = str_replace(' ', '_', ucwords(strtolower($customHandler))) . '_Custom_Handler';
         if (file_exists($handlersPath . DS . 'custom' . DS . $customHandlerClass . '.php')) {
             // Include the parent class
             include_once $handlersPath . DS . 'CustomHandler.php';
             // Include the handler file
             include_once $handlersPath . DS . 'custom' . DS . $customHandlerClass . '.php';
             $customHandler = new $customHandlerClass($this->item, $this->crtId);
             $customHandler->handle();
         }
     }
 }
 /**
  * Display a list of all option groups
  *
  * @return  void
  */
 public function displayTask()
 {
     $this->view->filters = array('sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'title'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'));
     $obj = new Archive();
     // Get record count
     $this->view->total = $obj->optionGroups('count', $this->view->filters);
     // Get records
     $this->view->rows = $obj->optionGroups('list', $this->view->filters);
     //print_r($this->view->rows); die;
     // For all records here get options
     $options = new \stdClass();
     $warehouse = new Warehouse();
     foreach ($this->view->rows as $r) {
         $key = $r->ogId;
         $allOptions = $warehouse->getOptionGroupOptions($key, 'rows', false);
         //print_r($allOptions); die;
         // Count how many active and how many inactive options there are
         $optionCounter = new \stdClass();
         $optionCounter->active = 0;
         $optionCounter->inactive = 0;
         foreach ($allOptions as $optionInfo) {
             if ($optionInfo->oActive) {
                 $optionCounter->active++;
             } else {
                 $optionCounter->inactive++;
             }
         }
         $options->{$key} = $optionCounter;
     }
     //print_r($options); die;
     $this->view->options = $options;
     // Set any errors
     if ($this->getError()) {
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
     }
     // Output the HTML
     //print_r($this->view); die;
     $this->view->display();
 }
Beispiel #5
0
 /**
  * Constructor
  * @param 	Object  Product info
  * @param   int     Cart ID
  * @param   int     User ID
  * @return 	Void
  */
 public static function getAuditor($pInfo, $crtId)
 {
     $pId = $pInfo->pId;
     $warehouse = new Warehouse();
     // Get product type
     $pType = $warehouse->getProductTypeInfo($pInfo->ptId);
     $type = $pType['ptName'];
     $model = $pType['ptModel'];
     // Find if there are auditors for this product's type and model
     $auditorsPath = dirname(__DIR__) . DS . 'lib' . DS . 'auditors';
     $auditorClass = str_replace(' ', '_', ucwords(strtolower($model))) . '_Auditor';
     if (file_exists($auditorsPath . DS . $auditorClass . '.php')) {
         // Include the auditor file
         require_once $auditorsPath . DS . $auditorClass . '.php';
         $className = "\\Components\\Cart\\Lib\\Auditors\\" . $auditorClass;
         return new $className($type, $pId, $crtId);
     } else {
         require_once $auditorsPath . DS . 'BaseAuditor.php';
         return new \Components\Cart\Lib\Auditors\BaseAuditor($type);
     }
 }
Beispiel #6
0
 /**
  * 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();
 }
Beispiel #7
0
 /**
  * View the order
  *
  * @return  void
  */
 public function viewTask()
 {
     // Incoming
     $id = Request::getVar('id', array(0));
     // Get transaction info
     $tInfo = Cart::getTransactionInfo($id);
     $tItems = unserialize($tInfo->tiItems);
     foreach ($tItems as $item) {
         // Check if the product is still available
         $warehouse = new Warehouse();
         $skuInfo = $warehouse->getSkuInfo($item['info']->sId);
         if (!$skuInfo) {
             // product no longer available
             $item['info']->available = false;
         } else {
             $item['info']->available = true;
         }
     }
     $tInfo->tiItems = $tItems;
     // Get user info
     $userId = Cart::getCartUser($tInfo->crtId);
     $user = Profile::getInstance($userId);
     //print_r($user); die;
     $this->view->user = $user;
     $this->view->tInfo = $tInfo;
     $this->view->tId = $id;
     $this->view->setLayout('view')->display();
 }
Beispiel #8
0
 /**
  * Releases locked transaction items back to inventory and marks the transaction status as 'released'
  *
  * @param int Transaction ID
  * @return void
  */
 public static function releaseTransaction($tId)
 {
     $db = \App::get('db');
     // Check if the transaction can be released (status is pending)
     // Get info
     $sql = "SELECT t.`tStatus` FROM `#__cart_transactions` t WHERE t.`tId` = {$tId}";
     $db->setQuery($sql);
     $db->query();
     if (!$db->getNumRows()) {
         return false;
     }
     // Get transaction items
     $tItems = self::getTransactionItems($tId);
     /* Go through each item and return the quantity back to inventory if needed */
     $warehouse = new Warehouse();
     if (!empty($tItems)) {
         foreach ($tItems as $sId => $itemInfo) {
             $qty = $itemInfo['transactionInfo']->qty;
             $warehouse->updateInventory($sId, $qty, 'add');
         }
     }
     // update status
     self::updateTransactionStatus('released', $tId);
 }
Beispiel #9
0
 /**
  * Check if everything checks out and the product is ready to go
  *
  * @param  	void
  * @return 	void
  */
 public function verify()
 {
     if (empty($this->data->name)) {
         throw new \Exception(Lang::txt('No product name set'));
     }
     // Check if the alias is used by another product (only if gets published, allow duplicates for unpublished items)
     $warehouse = new Warehouse();
     if ($this->getAlias() && $this->getActiveStatus()) {
         $otherProduct = $warehouse->checkProduct($this->getAlias(), true);
         if ($otherProduct->status > 0 && $otherProduct->pId != $this->getId()) {
             throw new \Exception(Lang::txt('There is another product with the same alias. Alias cannot be set.'));
         }
     }
     return true;
 }
Beispiel #10
0
 /**
  * Add collection to the warehouse
  *
  * @param  void
  * @return object	info
  */
 public function add()
 {
     $this->verify();
     $warehouse = new Warehouse();
     return $warehouse->addCollection($this);
 }
Beispiel #11
0
 /**
  * Edit a category
  *
  * @return  void
  */
 public function editTask($row = null)
 {
     Request::setVar('hidemainmenu', 1);
     $obj = new Archive();
     if (is_object($row)) {
         $id = $row->getId();
         // If this is a new option, set option group ID
         if (!$id) {
             $ogId = Request::getVar('ogId');
             $row->setOptionGroupId($ogId);
         }
         $this->view->row = $row;
         $this->view->task = 'edit';
     } else {
         // Incoming
         $id = Request::getVar('id', array(0));
         if (is_array($id) && !empty($id)) {
             $id = $id[0];
         }
         // Get option
         $row = $obj->option($id);
         $this->view->row = $row;
         // If this is a new option, set option group ID
         if (!$id) {
             $ogId = Request::getVar('ogId');
             $row->setOptionGroupId($ogId);
         }
     }
     //print_r($row); die;
     // Get option group's info
     $ogId = $row->getOptionGroupId();
     $warehouse = new Warehouse();
     $ogInfo = $warehouse->getOptionGroups('list', $filters = array('ids' => $ogId));
     $this->view->ogInfo = $ogInfo[0];
     //print_r($ogInfo); die;
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->setLayout('edit')->display();
 }
Beispiel #12
0
 /**
  * Edit a SKU
  *
  * @return  void
  */
 public function editTask($row = null)
 {
     Request::setVar('hidemainmenu', 1);
     $obj = new Archive();
     if (is_object($row)) {
         $id = $row->getId();
         // If this is a new SKU, set product ID
         if (!$id) {
             $pId = Request::getVar('pId');
             $row->setProductId($pId);
         }
         $this->view->row = $row;
         $this->view->task = 'edit';
     } else {
         // Incoming
         $id = Request::getVar('id', array(0));
         if (is_array($id) && !empty($id)) {
             $id = $id[0];
         }
         // Get correct SKU instance
         $pId = Request::getVar('pId');
         if ($id) {
             $row = Sku::getInstance($id);
         } elseif ($pId) {
             // create new SKU
             $row = Sku::newInstance($pId);
         } else {
             throw new \Exception('SKU was not found');
         }
         $this->view->row = $row;
     }
     // Get product's info
     $pId = $row->getProductId();
     $warehouse = new Warehouse();
     $pInfo = $warehouse->getProductInfo($pId, true);
     $this->view->pInfo = $pInfo;
     //print_r($pInfo); die;
     // Get available product-defined option groups and options
     $this->view->allOptions = $obj->getProductOptions($pId);
     // Get current SKU options
     $this->view->options = $row->getOptions();
     // Get number of downloads
     $downloaded = CartDownload::countSkuDownloads($id);
     $this->view->downloaded = $downloaded;
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->setLayout('edit')->display();
 }
Beispiel #13
0
 /**
  * User agreement acceptance
  *
  * @return     void
  */
 public function eulaTask()
 {
     $cart = new CurrentCart();
     $errors = array();
     $transaction = $cart->liftTransaction();
     if (!$transaction) {
         // Redirect to cart if transaction cannot be lifted
         $cart->redirect('home');
     }
     $nextStep = $cart->getNextCheckoutStep();
     // Double check that the current step is indeed EULA, redirect if needed
     if ($nextStep->step != 'eula') {
         $cart->redirect($nextStep->step);
     }
     // Get the SKU id of the item being displayed (from meta)
     $sId = $nextStep->meta;
     // Get the eula text for the product or EULA (EULAs are assigned to products, and if needed, SKUS)
     $warehouse = new Warehouse();
     $skuInfo = $warehouse->getSkuInfo($sId);
     $this->view->productInfo = $skuInfo['info'];
     // Check if there is SKU EULA set
     if (!empty($skuInfo['meta']['eula'])) {
         $productEula = $skuInfo['meta']['eula'];
     } else {
         // Get product id
         $pId = $skuInfo['info']->pId;
         // Get EULA
         $productEula = $warehouse->getProductMeta($pId)['eula']->pmValue;
     }
     $this->view->productEula = $productEula;
     $eulaSubmitted = Request::getVar('submitEula', false, 'post');
     if ($eulaSubmitted) {
         // check if agreed
         $eulaAccepted = Request::getVar('acceptEula', false, 'post');
         if (!$eulaAccepted) {
             $errors[] = array(Lang::txt('COM_CART_MUST_ACCEPT_EULA'), 'error');
         } else {
             // Save item's meta
             $itemMeta = new \stdClass();
             $itemMeta->eulaAccepted = true;
             $itemMeta->machinesInstalled = 'n/a';
             $cart->setTransactionItemMeta($sId, json_encode($itemMeta));
             // Mark this step as completed
             $cart->setStepStatus('eula', $sId);
             // All good, continue
             $nextStep = $cart->getNextCheckoutStep()->step;
             $cart->redirect($nextStep);
         }
     }
     if (!empty($errors)) {
         $this->view->notifications = $errors;
     }
     $this->view->display();
 }
Beispiel #14
0
 /**
  * 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;
 }
Beispiel #15
0
 /**
  * Instantiate the correct Sku for a given product
  *
  * @return     StorefrontModelProduct
  */
 private function instantiateSkuForProduct($sId, $pId)
 {
     $warehouse = new Warehouse();
     // If existing SKU, load the SKU, find the product, get the product type
     if ($sId) {
         $skuInfo = $warehouse->getSkuInfo($sId);
         $productType = $warehouse->getProductTypeInfo($skuInfo['info']->ptId)['ptName'];
     } else {
         $product = new Product($pId);
         $productType = $warehouse->getProductTypeInfo($product->getType())['ptName'];
     }
     // Initialize the correct SKU based on the product type
     if (!empty($productType) && $productType == 'Software Download') {
         require_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'SoftwareSku.php';
         $sku = new \Components\Storefront\Models\SoftwareSku($sId);
     } else {
         require_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'Sku.php';
         $sku = new \Components\Storefront\Models\Sku($sId);
     }
     // If this is a new SKU, set the product ID
     if (!$sId) {
         $sku->setProductId($pId);
     }
     return $sku;
 }
Beispiel #16
0
 /**
  * Update product info -- TODO: phase it out -- use save() instead
  *
  * @param  void
  * @return object	info
  */
 public function update()
 {
     $this->verify();
     $warehouse = new Warehouse();
     $return = $warehouse->updateProduct($this);
     $this->load();
     return $return;
 }
Beispiel #17
0
 /**
  * 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;
 }
Beispiel #18
0
 /**
  * Get category info
  *
  * @param      int $cId Category ID
  * @return     mixed category info
  */
 public function category($cId)
 {
     $warehouse = new Warehouse();
     $cInfo = $warehouse->getCollectionInfo($cId, true);
     return $cInfo;
 }
Beispiel #19
0
 /**
  * Get all items in the transaction
  *
  * @param int transaction ID
  * @return array of items in the transaction, false if no items in transaction
  */
 public static function getTransactionItems($tId)
 {
     $db = \App::get('db');
     $sql = "SELECT `sId`, `tiQty`, `tiPrice`, `tiMeta` FROM `#__cart_transaction_items` ti WHERE ti.`tId` = {$tId}";
     $db->setQuery($sql);
     $db->query();
     if (!$db->getNumRows()) {
         return false;
     }
     $allSkuInfo = $db->loadObjectList('sId');
     $skus = $db->loadColumn();
     $warehouse = new Warehouse();
     $skuInfo = $warehouse->getSkusInfo($skus);
     // Update skuInfo with transaction info
     foreach ($skuInfo as $sId => $sku) {
         $transactionInfo = new \stdClass();
         $transactionInfo->qty = $allSkuInfo[$sId]->tiQty;
         $transactionInfo->tiPrice = $allSkuInfo[$sId]->tiPrice;
         $transactionInfo->tiMeta = json_decode($allSkuInfo[$sId]->tiMeta);
         $skuInfo[$sId]['transactionInfo'] = $transactionInfo;
         unset($transactionInfo);
     }
     if (empty($skuInfo)) {
         return false;
     }
     return $skuInfo;
 }