public function handle()
 {
     $itemInfo = $this->item['info'];
     $itemMeta = $this->item['meta'];
     $itemCartInfo = $this->item['cartInfo'];
     // Check the serial management. If multiple -- need to update the transaction info items with the serials and mark the serials as used
     if (isset($itemMeta['serialManagement']) && $itemMeta['serialManagement'] == 'multiple') {
         // Get the required number of serials
         $serialsNeeded = $itemCartInfo->qty;
         require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'helpers' . DS . 'Serials.php';
         // Get the serial numbers
         $serialNumbers = \Components\Storefront\Helpers\Serials::issueSerials($itemInfo->sId, $serialsNeeded);
         $this->item['meta']['serials'] = $serialNumbers;
         // Update the transaction items with serials
         require_once dirname(dirname(dirname(__DIR__))) . DS . 'models' . DS . 'Cart.php';
         \Components\Cart\Models\Cart::updateTransactionItem($this->tId, $this->item);
     }
 }
Ejemplo n.º 2
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();
 }
Ejemplo n.º 3
0
 public function uploadcsvTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // See if we have a file
     $csvFile = Request::getVar('csvFile', false, 'files', 'array');
     $sId = Request::getVar('sId', '');
     if (isset($csvFile['name']) && $csvFile['name'] && $csvFile['type'] == 'text/csv') {
         if (($handle = fopen($csvFile['tmp_name'], "r")) !== FALSE) {
             $inserted = 0;
             $skipped = array();
             $ignored = array();
             while (($line = fgetcsv($handle, 1000, ",")) !== FALSE) {
                 if (!empty($line[0])) {
                     $serial = trim($line[0]);
                     $res = SerialsHelper::add($serial, $sId);
                     if ($res) {
                         $inserted++;
                     } else {
                         $skipped[] = $serial;
                     }
                 }
             }
             fclose($handle);
             $this->view->inserted = $inserted;
             $this->view->skipped = $skipped;
             $this->view->ignored = $ignored;
         } else {
             $this->view->setError('Could not read the file.');
         }
     } else {
         $this->view->setError('No file or bad file was uploaded. Please make sure you upload the CSV formated file.');
     }
     // Output the HTML
     $this->view->sId = $sId;
     $this->view->display();
 }