예제 #1
0
 /**
  * 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();
 }
예제 #2
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();
 }