/**
  * I am the singleton method
  *
  * @return PlentymarketsImportEntityItemStock
  */
 public static function getInstance()
 {
     if (!self::$Instance instanceof self) {
         self::$Instance = new self();
     }
     return self::$Instance;
 }
 /**
  * Retrieves the stocks for the stack
  */
 public function import()
 {
     // Unify
     $this->stack = array_unique($this->stack);
     if (empty($this->stack)) {
         return;
     }
     // Chunkify
     $stacks = array_chunk($this->stack, 100);
     // Reset
     $this->stack = array();
     // Warehouse
     $warehouseId = PlentymarketsConfig::getInstance()->getItemWarehouseID(0);
     // Build the request
     $Request_GetCurrentStocks = new PlentySoapRequest_GetCurrentStocks();
     $Request_GetCurrentStocks->Page = 0;
     //
     $ImportEntityItemStock = PlentymarketsImportEntityItemStock::getInstance();
     foreach ($stacks as $stack) {
         // Reset
         $Request_GetCurrentStocks->Items = array();
         // Add the SKUs
         foreach ($stack as $sku) {
             $RequestObject_GetCurrentStocks = new PlentySoapRequestObject_GetCurrentStocks();
             $RequestObject_GetCurrentStocks->SKU = $sku;
             $Request_GetCurrentStocks->Items[] = $RequestObject_GetCurrentStocks;
         }
         // Log
         PlentymarketsLogger::getInstance()->message('Sync:Item:Stock', 'Fetching ' . count($Request_GetCurrentStocks->Items) . ' stocks');
         // Do the request
         $Response_GetCurrentStocks = PlentymarketsSoapClient::getInstance()->GetCurrentStocks($Request_GetCurrentStocks);
         // Process
         /** @var PlentySoapObject_GetCurrentStocks $CurrentStock */
         foreach ($Response_GetCurrentStocks->CurrentStocks->item as $CurrentStock) {
             // Skip wrong warehouses
             if ($CurrentStock->WarehouseID != $warehouseId) {
                 continue;
             }
             $ImportEntityItemStock->update($CurrentStock);
         }
     }
 }
 /**
  * Updates the item stocks
  */
 public static function importItemStocks()
 {
     $Request_GetCurrentStocks = new PlentySoapRequest_GetCurrentStocks();
     $Request_GetCurrentStocks->LastUpdate = (int) PlentymarketsConfig::getInstance()->getImportItemStockLastUpdateTimestamp(0);
     $Request_GetCurrentStocks->Page = 0;
     $Request_GetCurrentStocks->WarehouseID = PlentymarketsConfig::getInstance()->getItemWarehouseID(0);
     PlentymarketsLogger::getInstance()->message('Sync:Item:Stock', 'LastUpdate: ' . date('r', PlentymarketsConfig::getInstance()->getImportItemStockLastUpdateTimestamp(0)));
     PlentymarketsLogger::getInstance()->message('Sync:Item:Stock', 'WarehouseId: ' . PlentymarketsConfig::getInstance()->getItemWarehouseID(0));
     // Helper
     $timestamp = time();
     $ImportEntityItemStock = PlentymarketsImportEntityItemStock::getInstance();
     do {
         $Response_GetCurrentStocks = PlentymarketsSoapClient::getInstance()->GetCurrentStocks($Request_GetCurrentStocks);
         foreach ($Response_GetCurrentStocks->CurrentStocks->item as $CurrentStock) {
             $ImportEntityItemStock->update($CurrentStock);
         }
         // Clear the models to avoid buffer overflows
         Shopware()->Models()->clear();
     } while (++$Request_GetCurrentStocks->Page < $Response_GetCurrentStocks->Pages);
     PlentymarketsConfig::getInstance()->setImportItemStockLastUpdateTimestamp($timestamp);
 }