protected function _renderResponse(Mage_Core_Controller_Response_Http $response, $data, $httpCode) { try { $content = Mage::helper('core')->jsonEncode($data); $response->setBody($content); $response->setHttpResponseCode($httpCode); } catch (Exception $e) { Mage::logException($e); $response->setBody('Undefined error'); $response->setHttpResponseCode(500); } }
/** * set Body * * @param string $content * @param string $name * @return $this */ public function setBody($content, $name = null) { // handle Checkout redirects if (strstr($content, 'paypal_standard_checkout') or strstr($content, 'clickandbuy_checkout') or strstr($content, 'payone_checkout') or strstr($content, 'moneybookers_checkout')) { echo $content; exit; } // not longer necessary because of the rewriting of the app Model we can change die Response Object everywhere //$this->ajaxHandler($content); parent::setBody($content, $name); return $this; }
/** * Append arbitrary content to the passed HTML element. * * @param string $tag * @param Mage_Core_Controller_Response_Http $response * @param string $content * @return void */ protected function _appendToHtmlTag($tag, Mage_Core_Controller_Response_Http $response, $content) { $response->setBody(str_replace('</' . $tag . '>', $content . '</' . $tag . '>', $response->getBody(false))); }
/** * Save the response body in the cache before sending it. * * @param Mage_Core_Controller_Response_Http $response * @param $lifetime * @return void */ public function httpResponseSendBefore(Mage_Core_Controller_Response_Http $response, $lifetime) { // Do not overwrite cached response if response was pulled from cache or cached response // was invalidated by an observer of the `diehard_use_cached_response` event if ($this->getUseCachedResponse() === NULL) { $cacheKey = $this->getCacheKey(); $tags = $this->helper()->getTags(); $tags[] = Cm_Diehard_Helper_Data::CACHE_TAG; $this->_getCacheInstance()->save($response->getBody(), $cacheKey, $tags, $lifetime); } // Inject dynamic content replacement at end of body $body = $response->getBody('default'); if ($this->useJs()) { $params = $this->extractParamsFromBody($body); if ($params) { // Replace params with rendered blocks $dynamic = $this->getDynamicBlockReplacement($params); $body = $this->replaceParamsInBody($body, $dynamic); } $response->setBody($body, 'default'); } }
protected function _send(Mage_Core_Controller_Response_Http $response, $data, $responseCode = 200) { $response->clearHeader('Location')->setHeader('Content-Type', 'application/json', true); $response->setHttpResponseCode($responseCode); $response->setBody(json_encode($data)); }