/** * 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(); }