Пример #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
 /**
  * Display a list of all users
  *
  * @return  void
  */
 public function displayTask()
 {
     // Get SKU ID
     $sId = Request::getVar('sId');
     $this->view->sId = $sId;
     // Get SKU
     $sku = Sku::getInstance($sId);
     $this->view->sku = $sku;
     // Get filters
     $this->view->filters = array('sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'srId'), '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'));
     //print_r($this->view->filters); die;
     // Get record count
     $this->view->filters['return'] = 'count';
     $this->view->total = SerialsHelper::getSkuSerials($this->view->filters, $sId);
     // Get records
     $this->view->filters['return'] = 'list';
     $this->view->rows = SerialsHelper::getSkuSerials($this->view->filters, $sId);
     // Output the HTML
     $this->view->display();
 }
Пример #3
0
 public function save()
 {
     // Update the inventory level for those SKUs that have multiple managed Serial Numbers.
     // The inventory should be tracked
     // The inventory level should always be equal to the number of available not-reserved serial numbers.
     $serialManagement = $this->getMeta('serialManagement');
     if ($serialManagement && $serialManagement == 'multiple') {
         $totalSerials = Serials::countAvailableSerials($this->getId());
         $this->setTrackInventory(true);
         $this->setInventoryLevel($totalSerials);
     }
     parent::save();
 }
Пример #4
0
 /**
  * Attempts to rebuild a transaction if there is enough inventory and prices have not changed
  *
  * @param void
  * @return bool Success or failure
  */
 private function rebuildTransaction()
 {
     // Go through each item in the transaction and see if it is available in quantity needed and if price has not changed
     $tItems = $this->getTransactionItems($this->cart->tId);
     foreach ($tItems as $item) {
         // Check price
         if ($item['info']->sPrice != $item['transactionInfo']->tiPrice) {
             // price changed
             return false;
         }
         // Check inventory
         if ($item['info']->sInventory < $item['transactionInfo']->qty) {
             // Not enough inventory
             return false;
         }
     }
     // lock transaction items
     $warehouse = $this->warehouse;
     require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Sku.php';
     foreach ($tItems as $sId => $item) {
         $sku = \Components\Storefront\Models\Sku::getInstance($sId);
         $sku->reserveInventory($item['transactionInfo']->qty);
         //$warehouse->updateInventory($sId, $item['transactionInfo']->qty, 'subtract');
     }
     parent::updateTransactionStatus('pending', $this->cart->tId);
     return true;
 }
Пример #5
0
 private function updateDependencies()
 {
     // Update SKUs' references for this product first
     Sku::updateReferences($this->getId());
     // Check all active product SKUs and disable those that do not verify anymore
     $skus = $this->getSkus();
     $skusDisabled = false;
     foreach ($skus as $sku) {
         if ($sku->getActiveStatus()) {
             try {
                 $sku->verify();
             } catch (\Exception $e) {
                 $sku->unPublish();
                 $skusDisabled = true;
             }
         }
     }
     if ($skusDisabled) {
         $this->addMessage('Some SKUs were unpublished because of the recent update. Check each SKU to fix the issues.');
     }
 }
Пример #6
0
 /**
  * Set the state of an entry
  *
  * @param      integer $state State to set
  * @return     void
  */
 public function stateTask($state = 0)
 {
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     $pId = Request::getVar('pId', 0);
     // Check for an ID
     if (count($ids) < 1) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $state == 1 ? Lang::txt('COM_STOREFRONT_SELECT_PUBLISH') : Lang::txt('COM_STOREFRONT_SELECT_UNPUBLISH'), 'error');
         return;
     }
     // Update record(s)
     $obj = new Archive();
     foreach ($ids as $sId) {
         // Save SKU
         try {
             $sku = Sku::getInstance($sId);
             $obj->updateSku($sku, array('state' => $state));
         } catch (\Exception $e) {
             $error = true;
         }
     }
     // Set message
     switch ($state) {
         case '-1':
             $message = Lang::txt('COM_STOREFRONT_ARCHIVED', count($ids));
             break;
         case '1':
             $message = Lang::txt('COM_STOREFRONT_PUBLISHED', count($ids));
             break;
         case '0':
             $message = Lang::txt('COM_STOREFRONT_UNPUBLISHED', count($ids));
             break;
     }
     $type = 'message';
     if (isset($error) && $error) {
         switch ($state) {
             case '1':
                 $action = 'published';
                 break;
             case '0':
                 $action = 'unpublished';
                 break;
         }
         $message = 'SKU could not be ' . $action;
         if (sizeof($ids) > 1) {
             $message = 'Some SKUs could not be ' . $action;
         }
         $type = 'error';
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=display&id=' . $pId, false), $message, $type);
 }
Пример #7
0
 /**
  * Releases locked transaction items back to inventory and marks the transaction status as 'released'
  *
  * @param int Transaction ID
  * @return void
  */
 public static function releaseTransaction($tId)
 {
     $db = \App::get('db');
     // Check if the transaction can be released (status is pending)
     // Get info
     $sql = "SELECT t.`tStatus` FROM `#__cart_transactions` t WHERE t.`tId` = {$tId}";
     $db->setQuery($sql);
     $db->query();
     if (!$db->getNumRows()) {
         return false;
     }
     // Get transaction items
     $tItems = self::getTransactionItems($tId);
     /* Go through each item and release the quantity back to inventory if needed */
     $warehouse = new Warehouse();
     if (!empty($tItems)) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Sku.php';
         foreach ($tItems as $sId => $itemInfo) {
             $qty = $itemInfo['transactionInfo']->qty;
             $sku = \Components\Storefront\Models\Sku::getInstance($sId);
             $sku->releaseInventory($qty);
         }
     }
     // update status
     self::updateTransactionStatus('released', $tId);
 }