Example #1
0
	protected function _performOrderExport()
	{
		if (!empty($this->_search)) {
			// there are search parameters, use them to filter customer data before exporting
			/** @var ISC_ADMIN_ORDERS */
			$orderClass = GetClass('ISC_ADMIN_ORDERS');
			$search = $orderClass->BuildWhereFromVars($this->_search);

			$where = ' WHERE 1=1 ' . $search['query'] . ' ';
			$join = $search['join'];

			unset($search);
		}
		else
		{
			$where = '';
			$join = '';
		}

		$query = 'SELECT /* Job_EmailIntegration_ModuleExport->_performOrderExport */ /*:columns*/ FROM `[|PREFIX|]orders` ' . $join . ' ' . $where;

		if (!$this->_skip) {
			$count = $this->_db->FetchOne(str_replace('/*:columns*/', 'COUNT(*)', $query));
			$this->_log->LogSystemNotice(array('emailintegration', $this->_module->GetName()), GetLang('EmailIntegration_Log_JobCommencingOrderExport', array(
				'count' => $count,
			)));
			$this->_keystore->set($this->_prefix . 'estimate', $count);
		}

		// no matter what the search specified, always order by id so new customers do not mess up the batch logic
		$query .= ' ORDER BY `orderid` LIMIT ';

		if ($this->_skip) {
			$query .= $this->_skip . ',';
		}

		$query .= self::BATCH_SIZE;

		$query = $this->_db->Query(str_replace('/*:columns*/', '`orderid`', $query));
		if (!$query) {
			$error = GetLang('EmailIntegration_Log_JobOrderDatabaseError');
			$this->_logError($error);
			$this->_errorExport($error);
			return false;
		}

		$batch = array();
		while ($row = $this->_db->Fetch($query))
		{
			$subscription = new Interspire_EmailIntegration_Subscription_Order($row['orderid']);
			$subscription->setDoubleOptIn($this->_doubleOptin);
			$subscription->setUpdateExisting($this->_updateExisting);
			$batch[] = $subscription;
		}
		unset($subscription);

		if (!empty($batch)) {
			$this->_logDebug('batch subscribing ' . count($batch) . ' orders');
			$this->_subscribeBatch($batch);
		}

		return count($batch);
	}