public function insertProducts($isInserting = true) { $url = Mage::getStoreConfig('factfinder/search/address'); $app = Mage::getStoreConfig('factfinder/search/context'); $login = Mage::getStoreConfig('kirchbergerknorr/factfindersync/auth_user'); $pass = md5(Mage::getStoreConfig('kirchbergerknorr/factfindersync/auth_password')); $prefix = Mage::getStoreConfig('factfinder/search/auth_advancedPrefix'); $postfix = Mage::getStoreConfig('factfinder/search/auth_advancedPostfix'); $timestamp = round(microtime(true) * 1000); $channel = Mage::getStoreConfig('factfinder/search/channel'); $hash = md5($prefix . $timestamp . $pass . $postfix); $wsdlUrl = sprintf("http://%s/%s/webservice/ws69/Import?wsdl", $url, $app); if (!$this->_products) { return false; } if ($isInserting) { $insertRecordRequest = array('in0' => $this->_products, 'in1' => $channel, 'in2' => true, 'in3' => array('password' => $hash, 'timestamp' => $timestamp, 'username' => $login)); $this->log('Connecting to WSDL'); $client = new SoapClient($wsdlUrl); try { $client->insertRecords($insertRecordRequest); $this->log('Records inserted'); $this->updateProductsDates($this->_ids, $this->_updateTime); } catch (Exception $e) { $this->log("Exception while importing: %s", $e->getMessage()); Mage::logException($e); $isExists = strpos($e->getMessage(), 'de.factfinder.indexer.importer.RecordAlreadyExistException'); $this->log("isExists: %s", $isExists); if ($isExists > -1) { preg_match("/Record with id '([^']+)'/is", $e->getMessage(), $matches); if (isset($matches[1])) { $skippedProductId = $matches[1]; $this->updateProductsDates(array($skippedProductId), date('Y-m-d H:i:s', strtotime('-90 minutes'))); $this->log("Skipping id %s", $skippedProductId); } } } } else { foreach ($this->_products as $product) { $this->log("Updating #%s", $product['id']); $updateRecordRequest = array('in0' => $product, 'in1' => $channel, 'in2' => true, 'in3' => array('password' => $hash, 'timestamp' => $timestamp, 'username' => $login)); $client = new SoapClient($wsdlUrl); try { $client->updateRecord($updateRecordRequest); $this->updateProductsDates(array($product['id']), $this->_updateTime); } catch (Exception $e) { $this->log("Exception: %s", $e->getMessage()); Mage::logException($e); $isNotExists = strpos($e->getMessage(), 'de.factfinder.indexer.importer.RecordNotFoundException'); $this->log("isNotExists: %s", $isNotExists); if ($isNotExists > -1) { preg_match("/Record with id '([^']+)'/is", $e->getMessage(), $matches); if (isset($matches[1])) { $skippedProductId = $matches[1]; $this->updateProductsDates(array($skippedProductId), 0); $this->log("Scheduled to insert id %s", $skippedProductId); } } } } } }