示例#1
0
文件: postsale.php 项目: Aziz-JH/core
 /**
  * Run the controller
  */
 public function run()
 {
     $objMethod = null;
     try {
         $strMod = $this->getModule();
         $intId = $this->getModuleId();
         if ($strMod == '' || $intId == 0) {
             \System::log('Invalid post-sale request (param error): ' . \Environment::get('request'), __METHOD__, TL_ERROR);
             $objResponse = new Response('Bad Request', 400);
             $objResponse->send();
         }
         switch (strtolower($strMod)) {
             case 'pay':
                 $objMethod = Payment::findByPk($intId);
                 break;
             case 'ship':
                 $objMethod = Shipping::findByPk($intId);
                 break;
         }
         if (null === $objMethod) {
             \System::log('Invalid post-sale request (model not found): ' . \Environment::get('request'), __METHOD__, TL_ERROR);
             $objResponse = new Response('Not Found', 404);
             $objResponse->send();
         }
         \System::log('New post-sale request: ' . \Environment::get('request'), __METHOD__, TL_ACCESS);
         if (!$objMethod instanceof IsotopePostsale) {
             \System::log('Invalid post-sale request (interface not implemented): ' . \Environment::get('request'), __METHOD__, TL_ERROR);
             $objResponse = new Response('Not Implemented', 501);
             $objResponse->send();
         }
         $objOrder = $objMethod->getPostsaleOrder();
         if (null === $objOrder || !$objOrder instanceof IsotopeProductCollection) {
             \System::log(get_class($objMethod) . ' did not return a valid order', __METHOD__, TL_ERROR);
             $objResponse = new Response('Failed Dependency', 424);
             $objResponse->send();
         }
         global $objPage;
         // Load page configuration
         if (!is_object($objPage) && $objOrder->pageId > 0) {
             $objPage = \PageModel::findWithDetails($objOrder->pageId);
             $objPage = \Isotope\Frontend::loadPageConfig($objPage);
         }
         // Set the current system to the language when the user placed the order.
         // This will result in correct e-mails and payment description.
         if ($GLOBALS['TL_LANGUAGE'] != $objOrder->language) {
             $GLOBALS['TL_LANGUAGE'] = $objOrder->language;
             \System::loadLanguageFile('default', $objOrder->language, true);
         }
         Isotope::setConfig($objOrder->getRelated('config_id'));
         if (($objCart = $objOrder->getRelated('source_collection_id')) !== null && $objCart instanceof Cart) {
             Isotope::setCart($objCart);
         }
         $objMethod->processPostsale($objOrder);
         $objResponse = new Response();
         $objResponse->send();
     } catch (\Exception $e) {
         \System::log(sprintf('Exception in post-sale request in file "%s" on line "%s" with message "%s".', $e->getFile(), $e->getLine(), $e->getMessage()), __METHOD__, TL_ERROR);
         $objResponse = new Response('Internal Server Error', 500);
         $objResponse->send();
     }
 }
示例#2
0
 /**
  * Run the controller
  */
 public function run()
 {
     $this->logRequest();
     $objMethod = null;
     try {
         $strMod = $this->getModule();
         $intId = $this->getModuleId();
         if ($strMod == '' || $intId == 0) {
             \System::log('Invalid post-sale request (param error): ' . \Environment::get('request'), __METHOD__, TL_ERROR);
             $objResponse = new Response('Bad Request', 400);
             $objResponse->send();
         }
         switch (strtolower($strMod)) {
             case 'pay':
                 $objMethod = Payment::findByPk($intId);
                 break;
             case 'ship':
                 $objMethod = Shipping::findByPk($intId);
                 break;
         }
         if (null === $objMethod) {
             \System::log('Invalid post-sale request (model not found): ' . \Environment::get('request'), __METHOD__, TL_ERROR);
             $objResponse = new Response('Not Found', 404);
             $objResponse->send();
         }
         \System::log('New post-sale request: ' . \Environment::get('request'), __METHOD__, TL_ACCESS);
         if (!$objMethod instanceof IsotopePostsale) {
             \System::log('Invalid post-sale request (interface not implemented): ' . \Environment::get('request'), __METHOD__, TL_ERROR);
             $objResponse = new Response('Not Implemented', 501);
             $objResponse->send();
         }
         /** @type Order $objOrder */
         $objOrder = $objMethod->getPostsaleOrder();
         if (null === $objOrder || !$objOrder instanceof IsotopeProductCollection) {
             \System::log(get_class($objMethod) . ' did not return a valid order', __METHOD__, TL_ERROR);
             $objResponse = new Response('Failed Dependency', 424);
             $objResponse->send();
         }
         Frontend::loadOrderEnvironment($objOrder);
         $objMethod->processPostsale($objOrder);
         $objResponse = new Response();
         $objResponse->send();
     } catch (\Exception $e) {
         \System::log(sprintf('Exception in post-sale request. See system/logs/isotope_postsale.log for details.', $e->getFile(), $e->getLine(), $e->getMessage()), __METHOD__, TL_ERROR);
         log_message(sprintf("Exception in post-sale request\n%s\n\n", $e->getTraceAsString()), 'isotope_postsale.log');
         $objResponse = new Response('Internal Server Error', 500);
         $objResponse->send();
     }
 }