/**
  * Main handler. Does all the checks
  *
  * @param 	void
  * @return 	void
  */
 public function audit()
 {
     /* If no user, some checks may be skipped... */
     // Get user
     $jUser = User::getRoot();
     // User specific checks
     if (!$jUser->get('guest')) {
         if ($sId = $this->getSku()) {
             // Check if the current user reached the max count of downloads for this SKU
             $sku = new Sku($sId);
             $skuDownloadLimit = $sku->getMeta('downloadLimit');
             if ($skuDownloadLimit > 0) {
                 // Get SKU download count
                 $skuDownloadCount = CartDownload::countUserSkuDownloads($this->sId, $this->uId);
                 // Check if the limit is reached
                 if ($skuDownloadCount >= $skuDownloadLimit) {
                     $this->setResponseStatus('error');
                     $this->setResponseNotice('You have reached the maximum number of allowed downloads for this product.');
                     $this->setResponseError(': you have reached the maximum number of allowed downloads for this product.');
                 }
             }
             return $this->getResponse();
         }
     }
     // Check SKU-related stuff if this is a SKU
     if ($sId = $this->getSku()) {
         // Check if SKU is reached the download max count
         $sku = new Sku($sId);
         $skuDownloadLimit = $sku->getMeta('globalDownloadLimit');
         if ($skuDownloadLimit > 0) {
             // Get SKU download count
             $skuDownloadCount = CartDownload::countSkuDownloads($this->sId);
             // Check if the limit is reached
             if ($skuDownloadCount >= $skuDownloadLimit) {
                 $this->setResponseStatus('error');
                 $this->setResponseNotice('This product has reached the maximum number of allowed downloads and cannot be downloaded.');
                 $this->setResponseError(': this product has reached the maximum number of allowed downloads and cannot be downloaded.');
             }
         }
         return $this->getResponse();
     }
     // Get product download limit
     $productDownloadLimit = Product::getMeta($this->pId, 'globalDownloadLimit');
     // Get product downloads count
     if ($productDownloadLimit > 0) {
         $productDownloadCount = CartDownload::countProductDownloads($this->pId);
         // Check if the limit is reached
         if ($productDownloadCount >= $productDownloadLimit) {
             $this->setResponseStatus('error');
             $this->setResponseNotice('This product has reached the maximum number of allowed downloads and cannot be downloaded.');
             $this->setResponseError(': this product has reached the maximum number of allowed downloads and cannot be downloaded.');
         }
     }
     return $this->getResponse();
 }
Esempio n. 2
0
 /**
  * Edit a category
  *
  * @return  void
  */
 public function editTask($row = null)
 {
     Request::setVar('hidemainmenu', 1);
     $obj = new Archive();
     // Get types
     $this->view->types = $obj->getProductTypes();
     // Get collections
     $this->view->collections = $obj->collections('list', array('sort' => 'cType'));
     // Get all option groups
     $this->view->optionGroups = $obj->optionGroups('list', array('sort' => 'ogName'));
     if (is_object($row)) {
         $id = $row->getId();
         $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];
         }
         // Load product
         $this->view->row = $obj->product($id);
     }
     // Get product option groups
     $this->view->productOptionGroups = $this->view->row->getOptionGroups();
     $this->view->config = $this->config;
     // Check if meta is needed for this product
     $pType = $this->view->row->getType();
     $this->view->metaNeeded = false;
     // Only software needs meta
     if ($pType == 30) {
         $this->view->metaNeeded = true;
     }
     // Get number of downloads
     $downloaded = CartDownload::countProductDownloads($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();
 }