/** * 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)); } }
/** * extends the checkout controller to show the trustedShops items * * @param \Enlight_Event_EventArgs $args * @return void */ public function onCheckoutPostDispatch(\Enlight_Event_EventArgs $args) { /** @var $subject \Enlight_Controller_Action */ $subject = $args->getSubject(); $view = $subject->View(); $request = $subject->Request(); $shopId = $this->shop->getId(); //get basic config of trusted shop for the seal template and trusted shop id $config = $this->getConfig($shopId); $basket = $view->sBasket; //if the current controller is the checkout controller extend the config for the basket if ($request->getActionName() != 'finish') { $this->controlBasketTsArticle($subject, $request, $basket['Amount']); } $basketConfig = $this->getTrustedShopBasketConfig($subject, $basket['Amount']); $config = array_merge($basketConfig, $config); $config['excellence'] = $this->tsSoapApi->checkCertificateTypeIfExcellence($shopId, false); if (isset($basket['content'])) { foreach ($basket['content'] as &$article) { $explode = explode('_', $article['ordernumber']); if (count($explode) == 4 && substr($explode[0], 0, 2) == 'TS') { $article['trustedShopArticle'] = true; } } //set delivery date $config['deliveryDate'] = $this->getDeliveryDate($basket['content']); } if ($request->getActionName() == 'finish') { $paymentName = $view->sPayment; $config['paymentName'] = $this->tsConfig->getTsPaymentCode($paymentName['name']); } //extend template $view->sTrustedShops = $config; if (!$this->isResponsiveTemplate()) { $this->template->addTemplateDir($this->bootstrapPath . 'Views/emotion'); $view->extendsTemplate('frontend/plugins/swag_trusted_shops/index/index.tpl'); $view->extendsTemplate('frontend/plugins/swag_trusted_shops/checkout/cart.tpl'); if ($request->getActionName() == 'finish') { $view->extendsTemplate('frontend/plugins/swag_trusted_shops/checkout/finish.tpl'); } } else { $this->template->addTemplateDir($this->bootstrapPath . 'Views/responsive'); } }
/** * 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; }