コード例 #1
0
ファイル: Bootstrap.php プロジェクト: nhp/shopware-4
	/**
	 * Checks the status of the trusted shops orders
	 *
	 * Status Description:
	 * Status 0 Pending
	 * Status 1 Success
	 * Status 3 Error
	 *
	 * @param \Shopware_Components_Cron_CronJob $job
	 * @return void
	 */
	public function onRunTSCheckOrderState(Shopware_Components_Cron_CronJob $job)
	{
		$this->prepareCronJob($job);
		$sql= "SELECT * FROM `s_plugin_swag_trusted_shops_excellence_orders` WHERE `status` = 0";
		$trustedShopOrders = Shopware()->Db()->fetchAll($sql);

		if(empty($trustedShopOrders)) {
			return true;
		}

		//get plugin basic config
		$config = $this->getTrustedShopBasicConfig();
		$tsDataModel = new TrustedShopsDataModel();

		//iterate the open trusted shop orders
		foreach($trustedShopOrders as $order) {
			$returnValue = $tsDataModel->getRequestState(array($config["id"], $order["ts_applicationId"]));
			switch(true) {
				case ($returnValue==0):
					$comment = $config["stateWaiting"]["description"];
					$status = $config["stateWaiting"]["id"];
					break;
				case ($returnValue>0):
					$comment = $config["stateSuccess"]["description"] . ' / Garantie-Nr.: ' . $returnValue;
					$status = $config["stateSuccess"]["id"];
					break;
				default:
					$comment = $config["stateError"]["description"];
					$status = $config["stateError"]["id"];
					break;
			}
			echo '<br>' . $order["ordernumber"] . ':  ' . $comment . '<br>';
			
			$sql = "UPDATE s_order SET status = ?, internalcomment = ? WHERE ordernumber = ?";
			Shopware()->Db()->query($sql, array($status, $comment, $order["ordernumber"]));
			
			$sql = "UPDATE s_plugin_swag_trusted_shops_excellence_orders SET status = ? WHERE id = ?";
			Shopware()->Db()->query($sql, array($returnValue, $order["id"]));
		}
		return true;

	}