Esempio n. 1
0
 /**
  * @param array $basket
  * @return int
  */
 private function getMaxDeliveryTime($basket)
 {
     // get the SwagTrustedShop config
     $config = $this->tsConfig->getSettings($this->shop->getId());
     $deliveryTime = $config['trustedShopsInStockDeliveryTime'];
     $notInStockDeliveryTime = $config['trustedShopsNotInStockDeliveryTime'];
     // if trustedShopsNotInStockDeliveryTime is defined check if any
     // article is not in stock
     if ($notInStockDeliveryTime > 0) {
         if ($this->isArticleNotInStock($basket)) {
             return $notInStockDeliveryTime;
         }
     }
     // if trustedShopsInStockDeliveryTime is defined return it
     if ($deliveryTime > 0) {
         return $deliveryTime;
     }
     $defaultReturn = 2;
     if (!$basket) {
         return $defaultReturn;
     }
     $shippingTimes = array_column($basket, 'shippingtime');
     if (!$shippingTimes) {
         return $defaultReturn;
     }
     $maxDeliveryTime = (int) max($shippingTimes);
     if (!$maxDeliveryTime) {
         return $defaultReturn;
     }
     return $maxDeliveryTime;
 }
Esempio n. 2
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));
     }
 }
Esempio n. 3
0
 /**
  * implements and performs the general soap request to Trusted Shops
  *
  * @param string $soapFunction
  * @param array $soapData
  * @param $shopId
  * @internal param $requestURLSuffix
  * @return string or int | soap resonse data
  */
 private function sendSoapRequest($soapFunction, array $soapData = null, $shopId)
 {
     define('SOAP_ERROR', -1);
     $settings = $this->tsConfig->getSettings($shopId);
     $ts_url = $settings['trustedShopsTestSystem'] ? 'protection-qa.trustedshops.com' : 'protection.trustedshops.com';
     //special url for protection request on save order
     $wsdlUrl = 'https://' . $ts_url . '/ts/protectionservices/ApplicationRequestService?wsdl';
     try {
         $client = new \Zend_Soap_Client($wsdlUrl);
         $returnValue = $client->__call($soapFunction, $soapData);
     } catch (\SoapFault $fault) {
         $returnValue = $fault->faultcode . ' ' . $fault->faultstring;
     }
     return $returnValue;
 }
Esempio n. 4
0
 /**
  * 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;
 }