/**
  * 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();
         }
     }
 }
Beispiel #2
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 #3
0
 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;
 }
Beispiel #4
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 #5
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;
 }