/** * 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(); }
/** * 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(); }
public function sku($sId) { $warehouse = new Warehouse(); if ($sId) { $skuInfo = $warehouse->getSkuInfo($sId); $productType = $warehouse->getProductTypeInfo($skuInfo['info']->ptId)['ptName']; } // Initialize the correct SKU if (!empty($productType) && $productType == 'Software Download') { require_once __DIR__ . DS . 'SoftwareSku.php'; $sku = new SoftwareSku($sId); } else { require_once __DIR__ . DS . 'Sku.php'; $sku = new Sku($sId); } return $sku; }
/** * 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(); }
/** * 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(); }
/** * 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; }
/** * 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; }
/** * 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; }