Exemplo n.º 1
0
 /**
  * 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));
     }
 }