/** * If the user confirm the order, this function sends the buyer protection request * * @param \Enlight_Event_EventArgs $args */ public function onSaveOrder(\Enlight_Event_EventArgs $args) { /* @var \sOrder $orderSubject */ $orderSubject = $args->getSubject(); $shopId = $orderSubject->sSYSTEM->sSubShop['id']; if ($this->isShopware50) { $shopContext = Shopware()->Container()->get('shopware_storefront.context_service')->getShopContext(); $shopId = $shopContext->getShop()->getId(); } $article = $this->isTsArticleInOrder($orderSubject); if (!empty($article)) { $config = $this->tsConfig->getTrustedShopBasicConfig($shopId); $returnValue = $this->tsSoapApi->sendBuyerProtectionRequest($orderSubject, $article['ordernumber'], $shopId); if (is_int($returnValue) && $returnValue > 0) { /* * Inserts the order to the trusted shops order table * The Status will be updated in the cronjob onRunTSCheckOrderState * Status Description: * Status 0 Pending * Status 1 Success * Status 3 Error */ $sql = "INSERT INTO `s_plugin_swag_trusted_shops_excellence_orders`\n\t\t\t\t\t\t(`ordernumber`, `shop_id`, `ts_applicationId`, `status`)\n\t\t\t\t\t\tVALUES (?,?,?,0)"; $this->db->query($sql, array($orderSubject->sOrderNumber, $shopId, $returnValue)); $comment = $config['stateWaiting']['description']; $status = $config['stateWaiting']['id']; } else { //failed $comment = $config['stateError']['description']; $status = $config['stateError']['id']; } $sql = "UPDATE s_order\n\t\t\t\t\tSET internalcomment = ?, status = ?\n\t\t\t\t\tWHERE ordernumber = ?"; $this->db->query($sql, array($comment, $status, $orderSubject->sOrderNumber)); } }
/** * 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 boolean */ public function onRunTSCheckOrderState(\Shopware_Components_Cron_CronJob $job) { $this->prepareCronJob($job); $sql = "SELECT *\n\t\t\t \tFROM `s_plugin_swag_trusted_shops_excellence_orders`\n\t\t\t \tWHERE `status` = 0"; $trustedShopOrders = $this->db->fetchAll($sql); $shopId = $trustedShopOrders['shop_id']; //get plugin basic config $config = $this->tsConfig->getTrustedShopBasicConfig($shopId); if (empty($trustedShopOrders)) { return true; } //iterate the open trusted shop orders foreach ($trustedShopOrders as $order) { $returnValue = $this->tsSoapApi->getRequestState(array($config['id'], $order['ts_applicationId']), $shopId); 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\n\t\t\t\t\tSET status = ?, internalcomment = ?\n\t\t\t\t\tWHERE ordernumber = ?"; $this->db->executeUpdate($sql, array($status, $comment, $order['ordernumber'])); $sql = "UPDATE s_plugin_swag_trusted_shops_excellence_orders\n\t\t\t\t\tSET status = ?\n\t\t\t\t\tWHERE id = ?"; $this->db->executeUpdate($sql, array($returnValue, $order['id'])); } return true; }
/** * returns the TrustedShops configuration for the submitted shopID * * @param $shopId * @return array */ private function getConfig($shopId) { return $this->tsConfig->getTrustedShopBasicConfig($shopId); }