/** * Loads the page configuration and language before generating a PDF. * * @param IsotopeProductCollection $objCollection */ protected function prepareEnvironment(IsotopeProductCollection $objCollection) { global $objPage; if (!is_object($objPage) && $objCollection->pageId > 0) { $objPage = \PageModel::findWithDetails($objCollection->pageId); $objPage = \Isotope\Frontend::loadPageConfig($objPage); \System::loadLanguageFile('default', $GLOBALS['TL_LANGUAGE'], true); } }
/** * 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(); } }